简体   繁体   中英

change event not firing after setting value dynamically

I want to bind change event to textarea(read only) whenever its value is set dynamically by opening popup window.

I am able to set the value, but the change event is not getting fired.

I used below code to bind change event to textarea :

$('textarea[name="Cordinator"]').bind("change", onChangeCordinator);
function onChangeCordinator(){}

How are you setting the value? By default the change event fires only if the value is changed by the browser user.

If you are setting the value programatically you need to use .trigger('change')

So somewhere in your onclick handler you need:

$('textarea[name="Cordinator"]').trigger('change');

there is a syntax error in your js

change this to

$('textarea[name="Cordinator"]').bind("change", onChangeCordinator);});

this

$('textarea[name="Cordinator"]').bind("change", onChangeCordinator);

UPDATE:

well you need to trigger it manually after setting the value on textarea like this

$('textarea[name="Cordinator"]').val('Set Your Value Here').trigger('change');

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM