javascript - Trigger the change of text in text box -
i unable trigger alter of text in current scenario.
if click on button changing content of text. how can trigger alter of text caused external event. illustration in click of button can able fill text in textbox, able paste texts , using mouse , keyboard. in these scenarios , scenarios these want event fired.
i have tried following.
$('#text_id').on('change', function () { alert('this not trigged when changed text'); });
the alert should come when text changed. there might many possible sources alter text.
this fiddle created.
thanks in advance.
this updated fiddle
updated fiddle - http://jsfiddle.net/upa2a/1/
$(document).ready(function () { $(document).on('click', "#button_id", function () { $('#text_id').val('text changed') }); $(document).on('change', "#text_id", function () { alert('this not trigged when changed text'); }); });
issues in original fiddle -
code has within$(document).ready()
missing ()
after function
incorrect utilize of $.on
(read more on http://api.jquery.com/on/) edit based on comment asked -
updated fiddle - http://jsfiddle.net/upa2a/4/
$(document).ready(function () { $(document).on('click', "#button_id", function () { $('#text_id').val('text changed').change(); }); $(document).on('change', "#text_id", function () { alert('this not trigged when changed text'); }); });
more edit based on comments thread -
from http://api.jquery.com/change "but other element types event deferred until element loses focus."
since, when changing via button click, text box wasn't focussed, trigger not happen automatically.
javascript jquery events textbox
No comments:
Post a Comment