View Single Post
Old 01-25-2013, 07:45 AM   PM User | #9
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 771
Thanks: 40
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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;
}
}
__________________
The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

Last edited by tpeck; 01-25-2013 at 07:48 AM..
tpeck is offline   Reply With Quote