PDA

View Full Version : Auto positiong cursor on form layout


inspiredmac
02-12-2003, 06:58 PM
Does anyone know the very brief code to have the viewer's cursor positioned in the first field of a form l ayout? An example would be the way Yahoo.com uses the function to place your cursor immediately into the field where a password is needed.

requestcode
02-12-2003, 08:12 PM
Use the onLoad event in your body tag to focus on the first form field. So if your form is named "myform" and your first field is named "phone_number" you would code it like this:
<BODY onLoad="document.myform.phone_number.focus()">

If you don't have a name for the form or the field then you can do this:

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

That would put the focus on the first form element in the first form of your document.

inspiredmac
02-12-2003, 08:20 PM
Thank you very much!:)