Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / July 2005



Tip: Looking for answers? Try searching our database.

Set focus to a text box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
steve - 30 Jul 2005 03:08 GMT
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.
McKirahan - 30 Jul 2005 03:21 GMT
> Hi,
>
[quoted text clipped - 14 lines]
>
> 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()">
RobG - 30 Jul 2005 06:49 GMT
[...]

> 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 );
   ...

Signature

Rob

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.