Just to finish off, using rnd me's example, this will work:
Code:
window.onload = function(){
// *****from rnd me ************************************
var store = (function() {
if (!location.protocol.match("data") && !window.localStorage) {
window.localStorage = {};
} //end webkit+ie8 patch
if (window.localStorage && !location.protocol.match("data")) {
function store(key, val) {
if (val) {
localStorage[document.domain][key] = val;
} else {
try {
var tm = localStorage[document.domain][key];
if (tm) {
tm = tm.toString();
}
} catch (rr) {
return "";
}
return tm;
}
return;
}
} else {
var store = function(key, val) {
if (val) {
setCookie(key, val);
} else {
return getCookie(key);
}
}
}
// *****************************************
var x = store('lesson'); // get 'lesson' key
//alert(x);
var theInputs = document.getElementsByTagName('input');
if(theInputs == null)
{
store('done', 'n');theInputs[i].value = 'n'; //alert("mmm");
}
for(var i = 0; i < theInputs.length; i++)
{
if(theInputs[i].type == 'text')
{
theInputs[i].onkeyup = function()
{
validate();store('done',value);
store(x,value);
var y = store(x);
alert('The value of the key \'lesson1\' is '+y);
}
}
theInputs[i].value = value;
}
}
function validate() {
var val = document.getElementById('done').value;
if (/[^yYnN]/.test(val)) {
alert ('Please enter Y or N');
document.getElementById('done').value = "";
return;
}
}