I am trying to assign an onKeyUp event to all inputs on the form using closure. the array fieldscontains all the field names that require the event assigned to them. The array ajaxFieldscontains the names of the fields (from the array fields) that require ajax validation.
function createEvents(fields,ajaxFields) {
for(var x=0;x<fields.length;x++) {
$('input[name='+fields[x]+']').keyup(function(field) {
return function() {
}(fields[x]));
}
}
I would like the onKeyUp function to be executed a second after the user has finished typing in this field, insted every time the key is up (onKeyUp). this will save a lot of processing space, not to mention ajax calls. While I use this:
clearTimeout(timer);
timer = setTimeout('validate()' ,1000);
You may have noticed that the function validate()does not exist, and that is because I do not know how to wrap the closure inside the named function, and I'm not even sure if I should ...
So how do I do this?
EDIT: fiddle