Skip to content

Instantly share code, notes, and snippets.

@newportandy
Created February 14, 2011 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newportandy/825330 to your computer and use it in GitHub Desktop.
Save newportandy/825330 to your computer and use it in GitHub Desktop.
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