javascript - Detecting input change in jQuery? -
when using jquery .change
on input
event fired when input loses focus
in case, need make call service (check if value valid) input value changed. how accomplish this?
updated clarification , example
examples: http://jsfiddle.net/pxfunc/5kpej/
method 1. input
event
in modern browsers use input
event. event fire when user typing text field, pasting, undoing, anytime value changed 1 value another.
in jquery this
$('#someinput').bind('input', function() { $(this).val() // current value of input field. });
starting jquery 1.7, replace bind
on
:
$('#someinput').on('input', function() { $(this).val() // current value of input field. });
method 2. keyup
event
for older browsers use keyup
event (this fire once key on keyboard has been released, event can give sort of false positive because when "w" released input value changed , keyup
event fires, when "shift" key released keyup
event fires no change has been made input.). method doesn't fire if user right-clicks , pastes context menu:
$('#someinput').keyup(function() { $(this).val() // current value of input field. });
method 3. timer (setinterval
or settimeout
)
to around limitations of keyup
can set timer periodically check value of input determine change in value. can use setinterval
or settimeout
timer check. see marked answer on question: jquery textbox change event or see fiddle working example using focus
, blur
events start , stop timer specific input field
Comments
Post a Comment