Reputation: 2563
I've a google map and i want to trigger a function whenever i select value from dynamic drop down . For that i added a listener and submitted the form like below.
var input = document.createElement('input');
input.setAttribute('type', 'text');
input.setAttribute('id', 'pac-input');
input.setAttribute('class', 'controls');
input.setAttribute('placeholder', 'Search By Area');
input.addEventListener("change", function(event) {
checkInputKey_map(event, $(this));
});
In checkInputKey
i'm sending ajax to controller with the selected value , but in post request parameter going is not the full name which was selected . instead it's the keywords written to get the places . while i want full search names to be sent . any help will be appreciated
update
function checkInputKey_map(event,this) {
if ((event.keyCode == 13 || event.type == 'change') && $("#API_source_map").val() == 'yelp_places') {
searched_place = $('#pac-input').val();
console.log(searched_place);
}
}
Upvotes: 2
Views: 1323
Reputation: 2563
It feels good but annoying always to post answer to your own question . but all things apart . I made a trick and i applied the same listener to the input but with a delay of one second . My final code is like below
var input = document.createElement('input');
input.setAttribute('type','text');
input.setAttribute('id','pac-input');
input.setAttribute('class','controls');
input.setAttribute('placeholder','Search By Area');
input.addEventListener("change", function(event){
setTimeout(function() {
checkInputKey_map(event, $(this));
},1000);
});
Upvotes: 1