javascript - storing user input in arrays for a log in site? -
i trying make mock site allow create username , password send array of usernames , passwords on log in page put in username or password , go threw process of checking weather wright or wrong , there. have realized when hit button send information on not register on other page. may please me find out screwed on.
here code create username , password:
<!doctype html> <html> <head> <title> create account </title> <script> function createlogin() { var usernamearray = document.getelementbyid("usernamemake").value; var paswordarray = document.getelementbyid("pwordmake").value; unarray.push("usernamearray"); pwarray.push("paswordarray"); localstorage.setitem("unarray", json.stringify([])); localstorage.setitem("pwarray", json.stringify([])); } </script> </head> <body> <form name = "makelogin"> <p class="log_on"> enter new username <input type="text" id="usernamemake"><br><br><br><br><br> enter new password <input type="text" id="pwordmake"> <input type="button" value="create it" id="submit" onclick="createlogin"> </p> </form> </body> </html>
here code logging in username , password:
<!doctype html> <html> <head> <title> log on page </title> <script type = "text/javascript"> var count = 2; function validate() { var un = document.getelementbyid("username").value; var pw = document.getelementbyid("pword").value; var valid = false; var unarray = json.parse(localstorage.getitem("unarray")); var pwarray = json.parse(localstorage.getitem("pwarray")); (var = 0; < unarray.length; i++) { if ((un == unarray[i]) && (pw == pwarray[i])) { valid = true; break; } } if (valid) { alert ("login successful"); window.location = "http://www.google.com"; return false; } var t = " tries"; if (count == 1) {t = " try"} if (count >= 1) { alert ("invalid username and/or password. " + "you have " + count + t + " left."); document.myform.username.value = ""; document.myform.pword.value = ""; settimeout("document.myform.username.focus()", 25); settimeout("document.myform.username.select()", 25); count --; } else { alert ("still incorrect! have no more tries left!"); document.myform.username.value = "no more tries allowed!"; document.myform.pword.value = ""; document.myform.username.disabled = true; document.myform.pword.disabled = true; return false; } } </script> <style> p.log_on{ position: fixed; top: 30px; left: 20px; } </style> </head> <body> <form name = "myform"> <p class="log_on"> enter user name <input type="text" id="username"><br><br><br><br><br> enter password <input type="password" id="pword"> <input type="button" value="check in" id="submit" onclick="validate()"> </p> </form> </body> </html>
in function create login you:
- you use undefined arrays
unarray
,pwarray
- you push arrays string not value of variables
- you save local storage empty array.
Comments
Post a Comment