javascript - Information not saving into Local Storage -


java script

function getid() {     'use strict';     var pass1, pass2;     pass1 = document.getelementbyid("pass1").value;     pass2 = document.getelementbyid("pass2").value;     if (pass1 !== pass2) {         window.alert("passwords not match");         document.getelementbyid("pass1").value = "";         document.getelementbyid("pass2").value = "";      } else {         logininfo[index] = {             fname: document.getelementsbyname("firstname").value,             lname: document.getelementsbyname("lastnane").value,             student: document.getelementsbyname("studentn").value,             password: document.getelementsbyname("password2").value         };         index++;         localstorage.setitem("login", json.stringify(logininfo));         window.location = "login.html";     } } 

html

<form>   <div class="login-card">     <img src="rsz_logo.gif" alt="north park logo" >      <h1>register</h1><br>     <input type="text" name="firstname" placeholder="first name" required>     <input type="text" name="lastname" placeholder="last name" required>     <input type="text" name="studentn" placeholder="student number" required>     <input type="password" name="pass1" placeholder="password" required>     <input type="password" name="pass2" placeholder="re-type password" required>      <input type="submit" name="login" class="login login-submit" value="register" onclick="getid()">      <div class="login-help">       <a href="login.html">back login</a>     </div>   </div> </form> 

what i'm trying here password validation see if pass1 = pass2, if equal proceed login page , store information local storage if not clear password fields person retype passwords.

the information doesn't save local storage. after click submit button page refreshes , information viable in url not in local storage. trying stick html , javascript.

you missing id tag needed this:

<input type="password" name="pass1" id="pass1" placeholder="password" required> <input type="password" name="pass2" id="pass2" placeholder="re-type password" required> 

this because using:

document.getelementbyid("pass1").value = ""; document.getelementbyid("pass2").value = ""; 

with no id, there's nothing function grab from.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -