Skip to content

Instantly share code, notes, and snippets.

@boyofgreen
Created March 26, 2012 16:47
Show Gist options
  • Save boyofgreen/2206439 to your computer and use it in GitHub Desktop.
Save boyofgreen/2206439 to your computer and use it in GitHub Desktop.
live form js
var pageMeter = document.querySelector('.completeMeter');
var checkMyValidity = function(){
var valueCollection = document.querySelectorAll('#RegisterUserForm input');
var myTotal = 0;
for (var i = 0; i< valueCollection.length; i++) {
//store it in local storage so it's there if they come back
localStorage[valueCollection[i].name] = valueCollection[i].value;
var isValid = valueCollection[i].checkValidity();
if(isValid === true){
myTotal += 20;
}
pageMeter.value = myTotal;
}
};
//check to see if supports it
if(document.createElement('progress').max !== undefined){
document.querySelector('.meterComponent').style.display = 'block';}
var myInputs = document.myForm.querySelectorAll('input');
for (var i = 0; i< myInputs.length; i++) {
myInputs[i].addEventListener(myInputs[i].type!=="checkbox"?'input':'change',checkMyValidity , false);
if(localStorage[myInputs[i].name] && localStorage[myInputs[i].name] !== 'undefined'){
myInputs[i].value = localStorage[myInputs[i].name];}
}
checkMyValidity();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment