I've got a fiddle for you: http://jsfiddle.net/pneebntd/3/
$(document).ready(function(){
$('#Address').focusout(ValidateAddress($(this).val(), "address"));
$('#City').focusout(ValidateAddress($(this).val(), "city"));
$('#State').focusout(ValidateAddress($(this).val(), "state"));
$('#Zipcode').focusout(ValidateAddress($(this).val(), "zip/postal code"));
$("#StateList").change(ValidateAddress($(this).val(), "state"));
});
function ValidateAddress(location, label) {
console.info("made it there : " + location + " " + label);
}
The short of it is that I'm (trying) to attach the event handler for a function I want to run when a control loses its focus (or when a dropdown changes value).
The way it's written, it fires on page load but never again after that. I've done this before but maybe it's just because it's Monday but... what am I doing wrong here?
This code
calls
ValidateAddressand passes its return value intofocusout, exactly the wayfoo(bar())callsbarand passes its return value intofoo.If you want to give a function to
focusout, you have to do that instead. For instance:That code creates a new anonymous function and passes that function reference into
focusout. When the event occurs, it will call yourValidateAddressfunction.