Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery change() doesnt work if the value is changed using jQuery

Tags:

jquery

I have a text input field which i have made readonly so the user can't type into it. I update the value of it with jquery though. So basically I want an event to fire when its value gets changed using jQuery. Below is an example of the input markup and jquery markup.

<input type="text" readonly="readonly" id="textinput" />

$('#textinput').change(function() {
    alert("It's Changed!");
});
like image 815
geoffs3310 Avatar asked Oct 24 '11 15:10

geoffs3310


1 Answers

You won't be able to do this. Changes made through code do not trigger events. You can simply call change directly in your code.

Something like this:

// do stuff
$('#textinput').val("something").change();
like image 166
James Montagne Avatar answered Oct 07 '22 01:10

James Montagne