
Untitled
By: a guest on
Dec 1st, 2012 | syntax:
HTML 5 | size: 0.75 KB | hits: 5 | expires: Never
Homepage:
<!DOCTYPE HTML>
<html>
<head>
<script>
function showStuff() {
if (localStorage["name"]) { //Only when the text exist,
document.getElementById("type").innerHTML = localStorage["name"] //Restore the text
}
}
window.onload = showStuff; //Restore
</script>
</head>
<body>
<div id="type">blah</div>
</body>
</html>
Form page:
<!DOCTYPE HTML>
<html>
<head>
<script>
function submitform(){
var textbox = document.getElementsByName('name')[0];
value = textbox.value;
localStorage["name"] = value; //save it in localStorage
}
</script>
</head>
<body>
Name: <input name="name"><br>
<button onclick="submitform();">Submit</button>
</body>
</html>