Reputation: 634
<div>
<center>
<form method="post" onsubmit="submit();">
<label for="fname">First Name:</label> 
<input type="text" id="fname" />
<br/>
<label for="lname">Last Name:</label> 
<input type="text" id="lname" />
<br/>
<label for="uname">User Name:</label> 
<input type="text" id="uname" />
<br/>
<label for="pass">Password:</label>  
<input type="text" id="pass" />
<br/>
<label for="dob">Date of Birth:</label>  
<input type="date" id="dob" />
<br/>
<label>Age:</label>     
<input type="text" id="age" />
<br/>
<span>Gender:</span>     
<input type="radio" name="gender" id="male" />
<label for="male">Male</label>
<input type="radio" name="gender" id="female" />
<label for="female">Female</label>
<br/>
<p>For what purpose(s) you are making account?</p>
<input type="checkbox" id="app" name="purpose" value="storingapps" />
<label for="app">Storing Apps</label>
<input type="checkbox" id="site" name="purpose" value="storingsites" />
<label for="site">Storing Sites</label>
<input type="checkbox" id="fun" name="purpose" value="fun" />
<label for="fun">Fun</label>
<br/>
<input type="submit" value="Submit" class="button" />
</form>
</center>
</div>
<script>
var labelsarray = document.getElementsByTagName("label");
var inputsarray = document.getElementsByTagName("input");
function submit() {
for (var i = 0; i < inputsarray.length - 1; i++) {
localStorage.setItem(labelsarray[i].innerHTML, inputsarray[i].value);
}
}
</script>
My form data is not storing in local storage of browser after submission please help me out.When I click on submit button it doesn't store data on local storage. When I remove function it works but to catch value of input I need to put it in a function.
Upvotes: 0
Views: 63
Reputation: 511
To fix your immediate code. Change the name of your callback to something other then submit
. submit()
is reserved, source - https://www.w3schools.com/js/js_reserved.asp.
Upvotes: 1