Posted By

chemical on 07/28/10


Tagged


Versions (?)

Select text in forms


 / Published in: HTML
 

  1. <!------>
  2.  
  3. <script type="text/javascript">
  4.  
  5. function select_field(id){
  6.  
  7. document.getElementById(id).focus();
  8. document.getElementById(id).select();
  9.  
  10. }
  11.  
  12. function init(){
  13. select_field('text1');
  14. }
  15.  
  16. onload=init;
  17.  
  18.  
  19.  
  20. This field gets selected onload:<br/>
  21. <input type="text" name="text1" id="text1" value="some text" />
  22.  
  23. <br/>
  24.  
  25. <textarea name="textarea1" id="textarea1" rows="9" cols="50" wrap="off">Some long
  26. content in here.
  27. abcd efgh abcd efgh abcd efgh
  28. abcd efgh abcd efgh abcd efgh
  29. abcd efgh abcd efgh abcd efgh
  30.  
  31. <br/>
  32.  
  33. <input type="button" value="Select text" onclick="select_field('textarea1')">
  34.  
  35. </form>

Report this snippet  

You need to login to post a comment.