views:

203

answers:

3

The code below 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 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?

A: 

something like this ?

function changeDB(database_name) {
    $('#sid_entry_box').autocomplete('option', 'source', "autocomplete_sid.php?database="+database_name);
}
Puaka
I do not want changing the database name to trigger autocomplete.I simply want my autocomplete function to have a function in it that reads the rf_database_option and passes it to the php function.Currently, the database name is passed as a get parameter but it gets set only when the html page is loaded.
abcParsing
its not to trigger but to change the database_name, so you can use the checkbox onchange event something like : ("input[name=rf_database_option]").change(function() { if($(this).is(':checked')) { changeDB($(this).val()); }
Puaka
A: 

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).

orip
I do not see how this implementation uses jquery's autocomplete from jQuery 1.4.2 and UI-1.8.The database name must be updated when the sid_entry_box changes.I will have to learn more about setOptions.
abcParsing
A: 

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.

abcParsing