Posted By

1man on 07/11/07


Tagged

form select focus


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

terriK
sumit270


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.