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


i'm using jquery autocomplete in 1 of forms.

the basic form selects products database. works great, i'd further develop products shipped zipcode returned. i've got backend script figured out. need work out best way pass zipcode script.

this how form looks.

<form>  <select id="zipcode">  <option value="2000">2000</option> <option value="3000">3000</option> <option value="4000">4000</option>  </select>  <input type="text" id="product"/>  <input type="submit"/>  </form> 

and here jquery code:

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

this code works extent. returns first zipcode value regardless of value selected. guess what's happening source url primed on page load rather when select menu changed. there way around this? or there better way overall achieve result i'm after?

you need use different approach source call, this:

$("#product").autocomplete({   source: function(request, response) {     $.getjson("product_auto_complete.php", { postcode: $('#zipcode').val() },                response);   },   minlength: 2,   select: function(event, ui){     //action   } }); 

this format lets pass whatever value when it's run, opposed when it's bound.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -