Saturday, 14 September 2013

why keyup don't fire with backspace in my case?

why keyup don't fire with backspace in my case?

I try to only let the user to register if they filled all of the fields
correctly.
I check whether the field has a valid class to determine whether all are
valid or not. Then using the on() to bind keyup focusout, i hide the
fakeButton and show the real working button.
var $inputs = $("input[type=text], input[type=password]");
$inputs.on("keyup focusout", function(){
if ( $inputs.filter('.valid').length === 4 ) {
$("#fakeButton").hide();
$("#send").css("display","block");
}else{
$("#fakeButton").show();
$("#send").css("display","none");
}
});
my partial html
<div>
<input type="button" id="fakeButton" value="Register"/>
<input type="button" id="send" name="send" value="Register"/>
</div>
the result: it's working fine when i fill up the field accordingly, from
top to bottom.. but something wrong when i go back and hit backspace on
the field, the class valid go away, the event don't show the fake button,
it delay.. (i need to focus or keyup one more time then it work)
http://www.photojoiner.net/JoinedImages/b2c0b64d-8da8-400a-a133-fec190bd6a83.jpg

No comments:

Post a Comment