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!

Making a button default

Status
Not open for further replies.

fpgiv

Programmer
Oct 1, 2003
91
US
Hi,
I have an <input type='submit'> that I want to be the default selected button when the page loads. Does anyone know how to do that?
Thanks!
~Phil
 
<body onload='document.getElementById("mySubmit").focus'>
<input type=submit id=mySubmit>
</body>

-kaht

banghead.gif
 

Just a quick ammendment - focus is a method, and so needs () after it:

Code:
<body onload="document.getElementById('mySubmit').focus();">
<input type="submit" id="mySubmit">
</body>

It that doesn't work in specific browsers, you might need to add in a tabIndex to your submit button:

Code:
<input type="submit" id="mySubmit" tabindex="1">

Hope this helps,
Dan
 
Whoops, thanks for the correction dan.

-kaht

banghead.gif
 
Also, if you only have on input and one button in a form, the button will automatically become the default when the user focuses on the input box, so that they can just fill in the input and press enter to submit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top