Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.