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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I assign focus to a input button 1

Status
Not open for further replies.

Triton001

Programmer
Jan 17, 2002
8
US
Hi,

It seems the focus() method is only used for the text, textare, checkbox and radio objects. I'm trying to give a button focus when the page is loaded but it does not seem to work. I'm getting an error telling me the button object does not exsist.

Any Ideas would be appreciated...thanks Mike

ERROR:
document.buttons.printButton is not object

CODE:
<HTML>
.
.
.
<SCRIPT>
document.buttons.printButton.focus();
</SCRIPT>
.
.
.
<FORM name=&quot;buttons&quot;>
.
.
.
<INPUT TYPE=&quot;button&quot; VALUE=&quot;Print Button&quot; NAME=&quot;printButton&quot; ONCLICK=&quot;window.print()&quot;>
.
.
</HTML>

 
put document.buttons.printButton.focus(); in the onload event of the body
<body onload=&quot;document.buttons.printButton.focus();&quot;>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top