There are a gazillion examples of how to set Focus to a form field in the <BODY ONLOAD..... but my page currently does other JavaScript in the OnLoad. But, when the page opens up, I need to set focus to a form field. What are my options??
not really the most recommended but you can place this after the closing form tag
<script language="javascript">
document.form name.field name.focus();
</script> _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
see the simple things pass before our eyes with a blank stare in space as we need to make things harder then they may appear.
good call sim777 _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
Okay, here's my issue... I'm putting his JavaScript into a head.asp page, and <BODY onload> is in body.asp and they're both #include files for my main ASP page. First, thanks for the responses thus far. I tried the script after the </form> tag and I also tried Body onload w/ a function. Neither one seems to work and I'm boggled. Is it because the function cannot find the form since it's in a dif page? Still not sure why onpnt's original idea won't work either because that's in the same page as the form. Hmmm. Thoughts????
Actually, ASPs files are processed on the server site. Browser gets the united code as one file. You can see it with View Source option of your browser. So, the problem is not there, the problem is on the client site.
Browser builds the page objects (DOM) dynamically while browser reads the HTTP stream. So, if you put the code such <script language="javascript">
document.form.field.focus();
</script>
in the HEAD section, it should not work, because the form objects are not built yet. However, you can put this code just after the form element you want to set focus on.
See the following code:
<HTML>
<HEAD></HEAD>
<BODY>
<form name=menufrm>
<input type="text" name=a value=""><br>
<input type="text" name=b value=""><br> <script>document.forms.menufrm.b.focus();</script>
<input type="text" name=c value=""><br>
<input type="submit" value="Submit It">
</BODY>
</HTML>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.