We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 07/11/07


Tagged

form select focus


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

terriK


Focus and Select a Form Input


Published in: JavaScript 


For forms with a default value onload you don't want your users to have to select the value, delete it and then insert their own input.

This function focuses on a selected input, then it selects the default text so the user can easily type their own value.

  1. /** @id codeFocus
  2. * @classDescription Focuses on the selected input and selects the value text.
  3. */
  4. var postcodeFocus = {
  5. grab:function(){
  6. if(!document.getElementById){return;};
  7. if(!document.getElementById('selected')){return;};
  8. var theInput = document.getElementById('selected');
  9. theInput.focus();
  10. theInput.select();
  11. }
  12. }

Report this snippet 

You need to login to post a comment.