Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(){}
like image 562
Sheetu Avatar asked Dec 21 '22 13:12

Sheetu


2 Answers

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');
like image 92
jfrej Avatar answered Feb 10 '23 05:02

jfrej


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

like image 45
rahul Avatar answered Feb 10 '23 05:02

rahul