Created
February 14, 2011 00:13
-
-
Save newportandy/825330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.observe("dom:loaded", function() { | |
$$(".things_you_want_to_validate").each(function(item) { | |
if(item.value) { | |
var x = parseFloat(item.value); | |
var handler = function(event) { | |
var element = Event.element(event); | |
var old_val = x; | |
var new_val = parseFloat(element.value); | |
if (isNaN(new_val) || new_val > (old_val * 1.2) || new_val < (old_val * .8)) { | |
element.addClassName('warning'); | |
} else { | |
element.removeClassName('warning'); | |
} | |
}; | |
item.observe('blur', handler); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment