i need help creating a password form in html/javascript -
i trying make password field , not working, if knew wrong with
code (probably because second project) grateful.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>password</title> <script> (function pw_check() { var $password; $password = document.write(document.getelementbyid("password")); if ($password = "pass") {window.open("alert.html");} else {window.open("pwfail.html");}; }); </script> <meta name="viewport" content="width=device-width; initial-scale=1.0"> </head> <body> <form> <input type="password"/> <button onclick="pw_check" id="password">submit</button> </form> </body> </html>
two problems:
onclick="pw_check();"
, otherwise you're referencing function not calling ityour
pw_check()
function kinds of wrong. try:function pw_check() { var pw = document.getelementbyid('password_input').value; if( pw == "pass") location.href = "alert.html"; else location.href = "pwfail.html"; }
and change form this:
<form> <input type="password" id="password_input" /> <button type="button" onclick="pw_check();">submit</button> </form>
Comments
Post a Comment