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!

Focus on load 1

Status
Not open for further replies.

glenmac

Technical User
Jul 3, 2002
947
CA
I'm having a brain fart and was hoping someone could help. What I want is probably as plain as the nose on my face. I want focus to be on a field in a form when the page loads.
This is what I tried.
Code:
<html> 
<head><title>Password</title>
<script>
function focus(){
form1.name.focus
}	
</script>

</head> 
<body bgcolor=&quot;#333399&quot;  text=&quot;#CCCCCC&quot; link=&quot;#009900&quot; vlink=&quot;#0099CC&quot; onload = &quot;focus();&quot;>
<div align = &quot;center&quot;>
<p> Enter your name and password</p> 

<form name = &quot;form1&quot; method=&quot;post&quot; action=&quot;/picsPW.asp&quot; > 
Your name: <input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot;><BR> 
Your Password: <input type=&quot;password&quot; name=&quot;pass&quot; size=&quot;15&quot;><BR> 
<input type=&quot;Submit&quot; value=&quot;Submit&quot;> 
</form> 
</div>
</body> 
</html>
I'm sure it's simple but I'm in a fog today.
 
function focus(){
form1.name.setfocus
}

instead of focus put setfocus

I tried it it works

Mtek13
 
Thanks Mtek . I knew it would be something simple.
 
Hmm tried it and can't get it to work for me. Can you paste your working code please.
 
the syntax for focus is focus(); and focus is a restricted word so I wouldn't recommend using it for the functions name.
lastly, you need to add document. to that to make it work in NN
try this
<html>
<head><title>Password</title>
<script>
function setfocus(){
document.form1.name.focus();
}
</script>

</head>
<body bgcolor=&quot;#333399&quot; text=&quot;#CCCCCC&quot; link=&quot;#009900&quot; vlink=&quot;#0099CC&quot; onload=&quot;setfocus();&quot;>
<div align = &quot;center&quot;>
<p> Enter your name and password</p>

<form name = &quot;form1&quot; method=&quot;post&quot; action=&quot;/picsPW.asp&quot; >
Your name: <input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot;><BR>
Your Password: <input type=&quot;password&quot; name=&quot;pass&quot; size=&quot;15&quot;><BR>
<input type=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>
</div>
</body>
</html> A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Great, thanks for the help (again!!) Onpnt. I should've known that.A Star for you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top