A user can enter an input value :
- by selecting one from a list (a json list is returned by file.php).
- or by typing one (we check if it exist with an ajax call, file2.php). If success (the value exist), then we call "geo".
The problem is that the "geo" function is called twice, because the change event is called after the select event.
Here is my code :
<input id="test">
$("#test").autocomplete({
minLength: 2,
source: "file.php",
select:function(event,ui){
var name = ui.item.value;
geo(name);
},
change: function (event, ui) {
$.ajax({
type:'POST',
async:false,
url:'file2.php',
data:{'name':$('#test').val()},
success:function(r){
o=JSON.parse(r);
geo(o.name);
}
});
}
});
I tried to add event.preventDefault(); like this :
select:function(event,ui){
var name = ui.item.value;
geo(name);
event.preventDefault();
},
but it doesn't work...
Any idea?