Html – Why is the HTML 5 localstorage not working

htmllocal-storage

I have created a simple html page to test the localstorage and for the life of me i cant get it to work, even though my firebug shows that the localstorage stored value as the one that i am storing here is my code for the first html page called Testhtml.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEsthtml.html</title>
</head>

<script >
function save()
{
var passvalue = document.getElementById('entry_1').value;
localStorage.setItem('passingvalue', passvalue);
}
</script>

<body>

<form action="simple.html"  method="POST">
<label  for="entry_0">Type ur name</label>
<input type="text" name="entry.0.single" value=""  id="entry_0">
<br> 
<label  for="entry_1">ur pets name
</label>
<label  for="entry_1">type something</label>
<input type="text" name="entry.1.single" value=""  id="entry_1">
<br>
<input type="submit" name="submit" id="submit" onClick="save()" value="Submit">
</form>
</body>
</html>

Second form called the simple.html code is as follows

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simple HTML</title>
<script >
function load()
{
var storedvalue = localstorage.getItem('passingvalue');
if(storedvalue)
{
document.getElementById('tb1').value=storedValue;
}
}
</script>
</head>

<body onload="load()" >

<input id="tb1" name="tb1" type="text"/>
<input type="submit" name="submit" id="submit" onClick="load()" value="Submit">

</body>
</html>

I try to run this code the simple.html which is the second form in the only textbox that is there it is not displaying anything..tried so many different things!!

Best Answer

It's just typographical errors in Simple.html on lines 8 and 9; 'localstorage' should be 'localStorage' and 'storedvalue' should be 'storedValue'.

You should look into your browsers error reporting and developer tools, they would have helped you solve this problem on your own. I personally prefer to develop on Google Chrome because of the fast, simple, and easy-to-use debug tools (if you use chrome, just press Ctrl+Shift+J).