0

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.

2
Contributors
6
Replies
29
Views
3 Years
Discussion Span
Last Post by diafol
0

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();
0

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.

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.