I have a zip code resolver and I’m using a keyup event handler to track when the length of the input reaches 5 then query the server to resolve the zip code. But I want to keep the script from being unnecessarily being called, so I was wonder if there were a way to track a keydown event and stop the keyup event when there is already 5 characters in the textbox (which would indicate that a query has probably already been submitted), if there were a way to stop the keyup event handler after? I know this is kind of a weird question so feel free to ask questions. Here kind of a layout of what I’m talking about:
$('#zip_resolver').live('keydown', function(event){
if($(this).val().length==5){
//STOP KEYUP EVENT
}else{
//DO NOTHING
}
});
$('#zip_resolver').live('keyup', function(){
if($(this).val().length==5){
//SEND RESOLVE REQUEST
}
});
You can just enforce that the keydown was 4: http://jsfiddle.net/rkw79/H7PhT/1/