Autocomplete and passing dynamic parameters

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

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

      

The database name is passed as a parameter to receive the php call.

This app has two databases selected by radio buttons. Since jQuery loads and assigns this function when the document is loaded, the database name is all that has been checked so far.

I really need to pass the php call:

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

      

Is there an easy way to understand the dynamic value of the dom?

+2


a source to share


3 answers


something like that?



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

      

+1


a source


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

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

      



You can see examples from setOptions

on this page (view source).

+1


a source


Puaka's solution works. Thanks!

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

Imagine you need to grab 10 different parameters from the DOM. This becomes a hassle for entering and changing 10 callback functions, each of which adds the ability to autocomplete.

Hopefully future jQuery documentation will show more examples of using the various autocomplete options.

0


a source







All Articles