I'm trying to fire a function whenever the value of an input field changes. The input field is in a lightbox so I have to delegate the event:
var validateDonation = function(elem) { var msg, value = elem.value; if (value == '') { msg = 'Please enter an amount'; } else if(parseInt(value, 10) < 1) { msg = 'Please enter an amount greater than 1'; } else if(parseInt(value, 10) > 100) { msg = 'Please enter an amount less than 100'; } else { msg = ''; } if(msg != '') { console.log(msg); } } and
$('body').delegate('#donation_amount', 'change', function(event) { validateDonation(this); }); If I use keyup instead of change the console log works just fine. But not on change. Why?