Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  3] [ 2]  / answers: 1 / hits: 30988  / 12 Years ago, tue, january 29, 2013, 12:00:00

I have a simple form like this:



<form method=post id=login>

Username: <input type=text value= name=usr />
Password: <input type=password value= name=pw/>
<input type=submit id=log name=log value=Login style=width:250px;/><br/>

</form>


But i keep getting cannot read property for my javascript with this line:



var usr = login.usr.value;
var pw = login.pw.value;


What is the reason i get this error ?


More From » javascript

 Answers
143

Try to give your form a name and change your code like below :



<form method=post id=login name=login>

Username: <input type=text value= name=usr />
Password: <input type=password value= name=pw/>
<input type=submit id=log name=log value=Login style=width:250px;/><br/>

</form>


and the in your javascript :



var usr = document.login.usr.value;


You can check here (jsfiddle link).


[#80540] Monday, January 28, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pranavrorys

Total Points: 466
Total Questions: 87
Total Answers: 115

Location: Barbados
Member since Sun, Nov 27, 2022
2 Years ago
pranavrorys questions
Fri, May 27, 22, 00:00, 2 Years ago
Thu, Oct 28, 21, 00:00, 3 Years ago
Sat, May 30, 20, 00:00, 4 Years ago
Fri, Dec 20, 19, 00:00, 5 Years ago
;