Page 1 of 1

Setting the focus on a form?

Posted: Wed Oct 16, 2002 2:51 pm
by jadair
How do I set the initial focus on a form? I know it's probably easy. I just don't know how to do it.

For example: I have a page with a set of edit boxes, but I need to jump to a certain edit box initially?

John

a little focus for you

Posted: Wed Oct 16, 2002 3:21 pm
by phpScott
If you are using an onload event handler you can within it use

someFormName.someTextFieldName.focus()

with the .focus() doing the work of setting the cursor to that location.
Works well to direct people to the incorrect field when doing client side error checking.

phpScott

Posted: Wed Oct 16, 2002 3:27 pm
by jadair
Thanks.

What is the syntex required for when I want multiple functions to execute onload?

onload="set_my_values() set_form_focus()"

multipe onLoad events

Posted: Wed Oct 16, 2002 3:49 pm
by phpScott
What I usually do is if I have multpile functions to call when the page is loading is to create an intialize function that then calls all the other functions I need to run.
function initialize()
{
firstfunction();
secondfunction();
and the like
}

then in the onload event handler I just call the initialize function.
This allows for greater flexability in which functions you might want to call, it centralize them and takes a bunch of code out of the body tag

phpScott

Posted: Wed Oct 16, 2002 4:20 pm
by jadair
Thanks.