Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which event raised when set value of input in JavaScript

When set value of input in JavaScript which event raised? I tried these event: (propertychange change keypress paste focus textInput input keyup keydown change). For example:

$('input').live/bind/on('which event', function() {
    //...
});
$('input')[0].value = "sd";
like image 465
Abbas Bafekr Avatar asked Sep 18 '25 00:09

Abbas Bafekr


2 Answers

When you set the value programmatically no event will be raised. You can raise it yourself though:

$('input')[0].value = "sd";
$('input').first().trigger("change");

Or just using jQuery:

$('input').first().val("sd").trigger("change");
like image 104
Matt Zeunert Avatar answered Sep 20 '25 14:09

Matt Zeunert


You can do something like this. You have to explicitly call change event.

$('input').val('New Value').change();
like image 40
Deepak Biswal Avatar answered Sep 20 '25 15:09

Deepak Biswal