Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: Possible to dynamically change source of Autocomplete widget?

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 });  }); 
like image 932
Ryan Avatar asked Aug 03 '10 17:08

Ryan


1 Answers

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 );     }); }); 
like image 162
PetersenDidIt Avatar answered Sep 25 '22 17:09

PetersenDidIt