Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery check if input value has changed dynamically

Tags:

jquery

I have to implement following issue. I have input and i need to show warning message if its value has changed. But for some reasons alert shows few times, can't figure out why. Here was the first question.

$("#input").bind("propertychange change paste input", function(){
    alert("Value has been changed");
});

The second question:

How can i check if input's value has changed dynamically. For example if i click on some element then value changes.

$("a").click(function(){
    $("#input").val("test");
})

Here's a fiddle i've created.

Any ideas? Thanks in advance!

like image 510
lalexa Avatar asked Aug 14 '14 07:08

lalexa


1 Answers

There is no event raised when an inputs value is changed dynamically. Your best option is to manually raise an event upon changing the value:

$("a").click(function(){
    $("#input").val("test").trigger('change');
})
like image 100
Rory McCrossan Avatar answered Nov 09 '22 06:11

Rory McCrossan