How do I pass an extra parameter to Jquery Autocomplete field?

前端 未结 8 1550
情书的邮戳
情书的邮戳 2020-12-08 12:41

I\'m using the JQuery Autocomplete in one of my forms.

The basic form selects products from my database. This works great, but I\'d like to further develop so that o

8条回答
  •  不知归路
    2020-12-08 13:27

    I believe you are correct in thinking your call to $("#product").autocomplete is firing on page load. Perhaps you can assign an onchange() handler to the select menu:

    $("#zipcode").change(resetAutocomplete);
    

    and have it invalidate the #product autocomplete() call and create a new one.

    function resetAutocomplete() {
        $("#product").autocomplete("destroy");
        $("#product").autocomplete({
             source:"product_auto_complete.php?postcode=" + $('#zipcode').val(),
             minLength: 2,
             select: function(event, ui){... }
        });
    }
    

    You may want your resetAutocomplete() call to be a little smarter -- like checking if the zip code actually differs from the last value -- to save a few server calls.

提交回复
热议问题