I am making a form which contain two input suggestion fields, 2 datepicker and three select fields. I want to make my form ajax based and show result in div when any field is changed. Just like farecompare.com I almost created a form but form start loading when i click any suggestion field. Is there a way to ajax live form when any value is changed from any field.
Using this code for select statments:
$(document).ready(function() {
$('#s1').change(function() {
$("#result").hide();
$("#loading").show();
$.get('ajax.php', $("#form").serialize(), function(data) {
$('#result').html(data);
$("#loading").hide();
$("#result").show();
});
});
});
This one is for suggestion input field:
$(document).ready(function() {
$("#to").on("change keyup paste click mouseout", function() {
setTimeout(function() {
$("#result").hide();
$("#loading").show();
$.get('ajax.php', $("#form").serialize(), function(data) {
$('#result').html(data);
});
}, 1000);
$("#loading").hide();
$("#result").show();
});
});
Mainly there is a problem coming on suggestion field. When user is typing on suggestion fields, ajax start posting when user click on that field, i want to post ajax when user user click the suggested text.