I am making a mobile web app using jquery mobile and jquery.
Now I have it so far that when I check my checkbox it saves my variables into the local storage from your browser. But it won’t put these variables back into my input fields.
Here is my script. The function validate() saves the variables into local storage.
$(document).ready(function () {
if (localStorage["mail"]) {
$('#mail').val(localStorage["mail"]);
}else{
$('#mail').val("");
}
if (localStorage["password"]) {
$('#password').val(localStorage["password"]);
}else{
$('#password').val("");
}
});
function validate(){
if ($("remember:checked")) {
var mail= $("#mail").val();
var password= $("#password").val();
localStorage["mail"] = mail ;
localStorage["password"] = password;
localStorage.setItem("mail", mail) ;
localStorage.setItem("password", password) ;
}else{
alert("You didn't check it! Let me check it for you.")
}
}
Can anybody help me ?
thank you
You are doing it wrong for setting and getting an item in local storage Use