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

Can't set focus on a password textbox... 2

Status
Not open for further replies.

VisualGuy

Programmer
May 27, 2003
162
US
The form name is FTDEntry, the password field is txtPasswordNew and yet when I run this:

document.FTDEntry.txtPasswordNew.focus();

...it tells me that document.FTDEntry.txtPasswordNew is null or not an object. Does anyone know why this is happening?
 
My crystal ball tells me you are doing that .focus() before the page loads up.

That's a total guess cause I don't see your code.

[monkey][snake] <.
 
Monksnake is likely correct. You need to set the focus to the password field in the onload function of the page.


For example, this fails:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>title test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

document.getElementById("blah").focus();

</script>
<style type="text/css"></style>
</head>
<body>

<input type="password" id="blah" />

</body>
</html>

But this works fine:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>title test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

[!]window.onload = function () {[/!]
   document.getElementById("blah").focus();
[!]};[/!]

</script>
<style type="text/css"></style>
</head>
<body>

<input type="password" id="blah" />

</body>
</html>

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
You were right...what I needed to do was give the password box an ID as well as a name. This seems to work. Thank you kaht...
 
No problem, but you should probably give monksnake a star too - he was the first person to answer the question (and gave the correct answer)

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Help you I will give, yes... mmmmm.....

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top