Rajaram Shelar
Rajaram Shelar

Reputation: 7877

Textbox text change event not firing when text changed from code

I have a textbox whose text is expected to be changed from the jquery code.

It is not firing when the value assinged from jquery code however it is firing when I change the text by key press.

Below is HTML and JQuery which i am using

<input type="text" id="txtProjectName"/>
 $("#txtProjectName").on('change keyup paste mouseup', function () {
        alert('Changed');
    });

What modifications would require here? please assist.

Upvotes: 3

Views: 1260

Answers (1)

Satpal
Satpal

Reputation: 133403

It is not firing when the value assinged from jquery code

Programmatically changing the value of an input doesn't fire its change event. You'll have to do that yourself using .trigger()

You need need to trigger change event when changing value from code

 $("#txtProjectName").val('Whatever').trigger('change');

Upvotes: 5

Related Questions