Reputation: 1672
I've got a little auto-suggest jQuery script. What it does is when I start typing it looks into my database for matches via an Ajax Post. When I click on a result the input field get the value wich I picked.
That works but what I want is to check if the value of the input has changed its value.
What i tried is
$("input").change(function(){
alert('change');
});
but it doesnt work.
Is there a way to check if a form input field has changed his value from an AJAX POST?
Upvotes: 2
Views: 1024
Reputation:
.changed
is not a function in jQuery.
Here the function is .change
use that:
$("input").change(function(){
alert('change');
});
Use the following function instead of above:
$(document).ready(function(){
$(".ui-autocomplete").click(function(){
alert("changed the input field.");
});
});
I am using the class ui-autocomplete
as you told that you are using the jQuery autocomplete. You can detect the name of class or id by using the firebug.
Upvotes: 3
Reputation: 4646
Only a few event types automatically activate a change event. For your particular application you may need to trigger the event manually as described below.
from the jquery documentation
The change event is sent to an element when its value changes. This event is limited to elements, boxes and elements.
To trigger the event manually, apply .change() without arguments:
$('#other').click(function() {
$('.target').change();
});
I wrote a small utility for myself which monitors object states and propagates state changes: Oculus. It is currently used only in a small client side project, but it's a simple enough pattern to be reusable.
Upvotes: 0