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.

Is there no one that can answer this question?

Member Avatar for diafol

You need to use onBlur instead of onChange (.blur) for textboxes.
In addition I don't think you need a timer function for the 'loading'.
Also, you may be able to combine a number of these change/blur functions:

$('#s1, #s2').change();

i want to run ajax after i pick date in datepicker

Member Avatar for diafol

i want to run ajax after i pick date in datepicker

That's not what you asked for...

Is there a way to ajax live form when any value is changed from any field.

i asked in my question that i want to ajax if any field is changes or filled again

Member Avatar for diafol

So what's stopping you from running it from the datepicker? Are you using a js-datepicker or a html5 version?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.