开发者

Autocomplete and Dynamic Parameter Passing

开发者 https://www.devze.com 2022-12-27 21:04 出处:网络
The code below works fine using jQuery UI 1.8 and jQuery 1.4.2 $(\"#sid_entry_box\").autocomplete({ source:\"开发者_StackOverflow中文版autocomplete_sid.php?database=\"+database_name,

The code below works fine using jQuery UI 1.8 and jQuery 1.4.2

$("#sid_entry_box").autocomplete({
  source:"开发者_StackOverflow中文版autocomplete_sid.php?database="+database_name,
  minLength:4,
  delay:1000,
  enable:true,
  cacheLength:1
});

The database name is passed as a get parameter of the php call.

In this application, there are two databases selected by radio buttons. Since jQuery loads and assigns this function when the document is loaded, the database name is whatever was checked at that momemnt.

What I really need to pass to the php call is the following:

database=$("input[name=rf_database_option]:checked").val();

Is there an easy to understand way to be able to pass a dynamic dom value?


something like this ?

function changeDB(database_name) {
    $('#sid_entry_box').autocomplete('option', 'source', "autocomplete_sid.php?database="+database_name);
}


When the radio button is changed, you can change the autocomplete source:

var database_name = ...;
$("#sid_entry_box").setOptions({
  source:"autocomplete_sid.php?database="+database_name
});

You can see examples with setOptions on this page (view the source).


Puaka's solution works. Thanks!

However, it seems to me that there should be a way within autocomplete to read in any DOM value and then pass that parameter to autocomplete which in turn is passed on to the php get routine.

Imagine if 10 different parameters need to be grabbed from the DOM. It becomes a challenge to go in and modify 10 callback functions each adding an option to the autocomplete function.

Hopefully, future documentation from jQuery will show more examples on use of the various options of autocomplete.

0

精彩评论

暂无评论...
验证码 换一张
取 消