HTML and JavaScript not working correcty -
i started learning javascript , have been on html time now. know have coded right javascript code log in form.
here javascript code:
<script> function login(){ var username=document.getelementbyid('usrnm'); var password=document.getelementbyid('pass'); if(username=="abc"){ if(password=="123"){ window.location.href="mypage.html" } else{ window.location.href="error.html" } else{ window.location.href="error.html" } } </script> and here html form:
<form name="input" method="get"> <b>username:</b> <br> <input id="usrnm" type="text" name="usrnm"> <br> <br> <b>password:</b> <br> <input id="pass" type="password" name="pswrd"> <br> <br> <center> <input id="login" type="image" src="login.png" value="login" onclick="login()"> when click on log in button. reloads same page in can see, intended call "mypage.html". i'mm starting learn javascript if there obvious reasons why code wont work, easy. =). know javascript works because when tried inserting onclick="login()" line <form name="input" method="get"> code directs me "error.html" when type on username field or password field.
you not getting element values, elements. add .value end of document.getelementbyid(id) method calls.
Comments
Post a Comment