Jquery ajax delay form submit

ajaxdelayformsjquerysubmit

I have this jquery ajax code that submits my form if it gets changed. My only problem is that I also have a country jquery selection in my form and everytime i click on the autocomplete suggestion the form with the old/last value get's submitted.
Example: I search for "Austria" and click on it and an empty value gets submitted. Then I change it to "Poland" and "at" for Austria is submitted.
My idea is to delay the ajax call: $.ajax but I couldn't find out how.

<script type="text/javascript">
$(document).ready(
function submitFormAjax()
{
    $('#myForm').change(function() {
        $.ajax({
            type:"POST",
            url:"ajax.php",
            data:$(this).serialize(),
            success:function(data)
            {
                $("#ajaxList").html(data);

            }
        })

      return false;
    });
});
</script>

Best Answer

setTimeout will do the work here:

$('#myForm').change(function() {
    var self = $(this);
    setTimeout(function () {
        $.ajax({
            type:"POST",
            url:"ajax.php",
            data:self.serialize(),
            success:function(data)
            {
                $("#ajaxList").html(data);

            }
        })
    }, 1000);
    return false;
});