Set focus to a text box

S

steve

Hi,


Here is my code to set focus on first input box.

<HTML><HEAD></HEAD>
<BODY><form name="f">
<input type=text name="n1">+
<input type=text name="n2">=
<input type=text name="sum">
<SCRIPT>
document.f.n1.focus()
</SCRIPT>
</form></BODY></HTML>

When I open the page and type something, nothing happens. How to make
it work?

Thanks.
 
M

McKirahan

steve said:
Hi,


Here is my code to set focus on first input box.

<HTML><HEAD></HEAD>
<BODY><form name="f">
<input type=text name="n1">+
<input type=text name="n2">=
<input type=text name="sum">
<SCRIPT>
document.f.n1.focus()
</SCRIPT>
</form></BODY></HTML>

When I open the page and type something, nothing happens. How to make
it work?

Thanks.

It works for me under IE and FF.

However, <SCRIPT> should be <SCRIPT type="text/javascript">

Alternatively, you could remove the <SCRIPT> section and
change the <BODY> tag to <BODY onload="document.f.n1.focus()">
 
R

RobG

McKirahan wrote:
[...]
It works for me under IE and FF.

However, <SCRIPT> should be <SCRIPT type="text/javascript">

Alternatively, you could remove the <SCRIPT> section and
change the <BODY> tag to <BODY onload="document.f.n1.focus()">

Works for me too with Safari and Firefox on Mac.


Try moving the script outside the form (you may not be able to get a
reference to it since it isn't finished yet) or create a delay using:

...
setTimeout( 'document.f.n1.focus()', 10 );
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top