Greetings,
I am using the official Autocomplete jquery widget and am having troubles dynamically changing a variable (selectType) I'm passing via the query string. The variable would change depending upon which option is selected via a select box.
$(function() { var selectType = $('#selectType option:selected').attr("value"); $("#selectType").change(function(){ selectType = $('#selectType option:selected').attr("value"); alert (selectType); // alerts the right value for debugging }); $("#address").autocomplete({ source: "ajaxSearchForClientAddress.php?selectType="+selectType, minLength: 3 }); });
Try actually changing the source
option of the autocomplete on the change event.
$(function () { var select = $( "#selectType" ), options = select.find( "option" ), address = $( "#address" ); var selectType = options.filter( ":selected" ).attr( "value" ); address.autocomplete({ source: "ajaxSearchForClientAddress.php?selectType=" + selectType, minLength: 3 }); select.change(function () { selectType = options.filter( ":selected" ).attr( "value" ); address.autocomplete( "option", "source", "ajaxSearchForClientAddress.php?selectType=" + selectType ); }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With