Morta1
Morta1

Reputation: 619

Catching a value change inside an input

I have an input that suppose to contain a name, the input has change and keyup events bounded to itself, at some point in my code i'm setting the value of the input myself, but the change/keyup event doesn't catch the changed value inside the input.

here's a snippet:

 <input class="form-control inp-playlist-name" type="text" name="playlist" value="" placeholder="e.g. Have a Nice Day">


$('.inp-playlist-name').bind('change keyup', function(){
//do something
});

//at some point i change the value
$('.inp-playlist-name').val('A value');

is there any other event that can catch that kind of change?

Upvotes: 0

Views: 43

Answers (1)

Ouroborus
Ouroborus

Reputation: 16875

There's no change event if you use Javascript to change the field's value. Instead, you can trigger the event yourself after making the change.

$('.inp-playlist-name').val('A value').trigger('change');

(Keep in mind that, if you're not careful, it's possible to end up with an infinite loop when doing this.)

Upvotes: 2

Related Questions