Focus OnLoad in JavaScript


/ Published in: JavaScript
Save to your folder(s)

You can put the user's cursor inside a text box or put focus on select box as soon as your page is loaded. This helps ensure that visitors do not 'overlook' an important form item on your site and this snippet only uses one line of code!


Copy this code and paste it in your HTML
  1. <!-- This part goes into your body tag -->
  2. <body OnLoad="document.myform.user.focus();">
  3.  
  4. <!-- You you just use the name of the form and field name within your form -->
  5. <form name="myform">
  6. Name: <input type="text" name="user" size="10">
  7. Email: <input type="text" name="email" size="10">
  8. </form>
  9.  
  10. </body>

URL: http://www.apphp.com/index.php?snippet=javascript-focus-on-load

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.