Jin Yong
Jin Yong

Reputation: 43788

How can I make the onchange event work for the text input box update by the javascript/Jquery?

Does anyone know how can I make the onchange event work for the text input box update by the javascript/Jquery?

Example:

Instead of manually key in the text into the input box, I will insert the value into the text box by using jquery as below. Any way that the onchange event will work once the value been change in the text box by jquery? Any way I can make it work?

HTML:

<table>
  <tr>
    <td>
       <input type="text" ID="test" />
    </td>
  </tr>
</table>

Javascript:

$(".test").val("ABC");


$('.test').change(function () {
    alert('hello')
});

Upvotes: 2

Views: 122

Answers (1)

rink.attendant.6
rink.attendant.6

Reputation: 46307

Trigger it:

$('.test').change(function () {
    alert('hello');
});

$(".test").val("ABC");
$('.test').trigger('change');

Upvotes: 2

Related Questions