Thursday 15 March 2012

javascript - On input change event? -



javascript - On input change event? -

when using jquery .change on input event fired when input loses focus

in case, need create phone 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 utilize 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 utilize keyup event (this fire 1 time 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 alter 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 alter in value. can utilize setinterval or settimeout timer check. see marked reply on question: jquery textbox alter event or see fiddle working illustration using focus , blur events start , stop timer specific input field

javascript jquery html

No comments:

Post a Comment