PDA

View Full Version : How to foucs on the first input field when a form is initial loaded


wty
07-01-2002, 07:20 PM
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

tamienne
07-01-2002, 07:32 PM
<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.

Zvona
07-02-2002, 08:31 AM
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 :
<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>

dwbh
07-03-2002, 03:35 PM
BTW, You can also use the TABINDEX (http://www.w3.org/TR/REC-html40/interact/forms.html#adef-tabindex) property of the HTML INPUT tag.

wty
07-16-2002, 04:43 PM
Hi All,

Thank you very much for your response! It works.