Web Analytics Made Easy -
StatCounter How to foucs on the first input field when a form is initial loaded - CodingForum

Announcement

Collapse
No announcement yet.

How to foucs on the first input field when a form is initial loaded

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to foucs on the first input field when a form is initial loaded

    Hi,

    It may sound simple to you. How can I get the first input field focused when a form is INITIALLY loaded?

    Thanks in advance!

    wty

  • #2
    <BODY onLoad="document.forms[0].elements[0].focus()">

    That's assuming it's the first form and it's the first element. You can change the numbers around to fit what you need.

    Comment


    • #3
      Just remember this can be frustrating to an end-user with slow connection (usability issue):

      When the form has loaded, but parts of the page are still loading/rendering, user starts inputting data in fields. He/she may have filled nearly all the entries and keeps inputting, when suddenly pages completes loading and throws the cursor back in the first input element. User just keeps writing staring at the keyboard (this is what most novice users does (eg. Your mother)) and he/she inputs his/her password to the name field.

      Thus, it'd be good to determine whether user has already started inputting data in fields before focusing to the first input element. Or you could write a code :
      Code:
      <form name="myForm" action="">
      	<input type="text" name="userName" />
      	<script type="text/javascript">
      		document.myForm.userName.focus();
      	</script>
      	<br />
      	<input type="password" name="userPW" />
      </form>
      Zvona
      First Aid for
      Web Design

      Comment


      • #4
        BTW, You can also use the TABINDEX property of the HTML INPUT tag.

        Comment


        • #5
          Hi All,

          Thank you very much for your response! It works.

          Comment

          Working...
          X