5

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!

3 Answers 3

7

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');
})
Sign up to request clarification or add additional context in comments.

2 Comments

thank you, what about first question?Alert windows shows few times: first - when i'm typing something, second - when i unfocused input
It shows once for each event fired. You have attached it to multiple events. The change event fires when the element is unfocussed.
0

There is no event for that instead you have to use trigger the change event

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

DEMO

1 Comment

thank you, what about first question?Alert windows shows few times: first - when i'm typing something, second - when i unfocused input
0

When value change value dynamically then you should bind event with element, see below sample

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.