to set extraParams dynamically to the current value of other dom elements, assign a function to the extraParams that retrieves the value from the dom, e.g.
$("#state").autocomplete(url, { extraParams: { town: function() { return $("#town").val(); } } }); see http://docs.jquery.com/Plugins/Autocomplete#Dependencies_between_fields alternatively, you can assign a static value, that of the input then the autocomplete() method was involked (probably at page steup time), using MorningZ's code quoted below. now, to address your other question, if you also have: $("#town").autocomplete(url, { extraParams: { state: function() { return $("#state").val(); } } }); then your backend at url can infer which input the user is typing into from the GET parameter names sent. but if you want, you could add another static parameter to explicitly say what is being sent in the q parameter rather than inferring from the other parameter names, e.g.: $("#state").autocomplete(url, { extraParams: { qis: 'state', town: function() { return $("#town").val(); } } }); $("#town").autocomplete(url, { extraParams: { qis: 'town', state: function() { return $("#state").val(); } } }); On 6/28/09 3:23 PM, "MorningZ" <morni...@gmail.com> wrote: > > Use AutoComplete's "extraParams" hook > > http://docs.jquery.com/Plugins/Autocomplete/autocomplete#toptions > > so it would be like: > > $("your state search textbox").autocomplete( > "/ajax/location.php", > { extraParams: { type: $("#state").val() } } > ); > > > > On Jun 26, 12:34 pm, 01101010001010001010 <herrbenn...@gmail.com> > wrote: >> Hi, >> >> First of all, thanks for the autocomplete code - it's excellent. >> Apologies if this next question is too simple, but I couldn't get the >> answer on google (lmgtfy.com) >> >> I have two autocomplete fields, for address-matching, which for the >> sake of argument could be called state and town. >> >> I have autocomplete on state go to /ajax/location.php?type=state and >> autocomplete on town go to /ajax/location.php?type=town >> >> My location.php script works fine delivering autocomplete results for >> each field individually. >> >> I want to pass the contents of ${#state} to the script when >> autocompleting town (so it will only autocomplete for towns in the >> already-chosen state). >> >> I can't see how to tell autocomplete to pass ${#state}.val in the call >> for town. >> >> Any thoughts gratefully received - and thanks again for the brilliant >> code. >> >> Peter