Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Place Cursor in First Form Field 4

Status
Not open for further replies.

CTekMedia

Programmer
Oct 5, 2001
634
US
Okay folks here is an easy one. I'm being lazy but I know ya'll can answer this without thinking. I have a page with a form. I want the cursor to locate itself into the first form field automatically when the page loads. I can't remember how :-o Never knew? lol

TIA Peace
BT
 
Hi Tia,

This is an easy question and I guess I'm the only one who can answer you at the moment. The way I did mine is to create a function call onLoad() and call it in the body of your HTML script. Something like this:

Function onLoad()
{
(yourFormName).info.document.(fieldName).setFocus();
}

<Body load=&quot;onLoad();&quot;>

It's been several months since I did any coding so if you see any flaws don't worry about it. You should get my general idea. One thing I wanted to add, that word &quot;info&quot; in the line above is what I called my onSubmit within my form to make sure that it would call that function.

Good Luck,
Candie ;o)

&quot;Mere distances between 2 people bring you all that much closer in the end!&quot;
 
Just this works for me - although please note Candie's looks very good as well.

<body leftmargin=&quot;0&quot; topmargin=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; onLoad=&quot;document.form1.txtUserName.focus()&quot;>

form1 is the name of your form for wherever the text box is in.

txtUserName is the name of the text box you want the focus to be in. &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Variety is always good - similar to candie's method you could set a variable in the head section

<script>
loadVar = &quot;document.forms['formname'].elements['fieldname'].focus();&quot;
</script>

then..

<body onLoad=&quot;eval(LoadVar);&quot;>

Reesy, Blood, Sweat But No Tears!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top