PDA

View Full Version : Very simple, but VERY important Javascript & Forms question


dutchtechno
08-15-2003, 10:59 AM
Call me a newbie ;) but I have this one little problem I just can`t find a solution for, here`s the deal:

When having a form on a webpage, I want the cursor to focus on the first field. Like you have with the ie. hotmail login. I remember that you should be able to do this easily with javascript, but I just can`t find the code for this.

Anyone out there that can help me with this? greatly appriciated!

greetz, Joost from Amsterdam

John76
08-15-2003, 11:32 AM
I think this might be what you are looking for:

http://javascript.internet.com/forms/form-focus.html

requestcode
08-15-2003, 12:33 PM
You could also use the onLoad event in the body tag to place the cursor in the first form field like this:
<body onLoad="document.form_name.field_name.focus()">

If the form and the field do not have names then this will also work if the form is the first or only one on your page:
<body onLoad="document.forms[0].elements[0].focus()">

dutchtechno
08-15-2003, 12:36 PM
thanks allot for the fast reply ;) byeee