views:

417

answers:

2

Hi everyone...

I have been able to get the jQuery autosuggest working without any problems, and I was just wondering if the results can be based on a combination of 2 form fields?

Let me try and explain a little better! I have a form with a keyword text entry box and a select list with a list of countries.

I'd like to provide suggestions for the chosen keyword search term, but also limit those suggestions to the country chosen from the dropdown (if changed) ...is this possible?

I hope I have explained my question okay! Any advice on this would be most appreciated!

cheers! Declan

+4  A: 

You can combine the value of the dropdown with what the user types into the textbox and submit it as one string to your PHP/ASP server-side code. For example, something like this:

$("#textbox").change(fetchKeywords);

function fetchKeywords()
{
    var string=$("#textbox").val() + "||" + $("#select").val();
    $.post("auto-suggest.php",{keyword:string});
}

This would give you a string such as "My keyword||USA". You could then use the explode() (if using PHP), or String.split() function to split the keyword and country code using the || seperator.

Note: I haven't used this particular jquery plugin, so you'll have to change the fetchKeywords() function a bit to make it work with that plugin.

Click Upvote
A: 

Hey... thanks for that! Gonna fiddle around with the code now!

Just out of curiousity... has anybody seen this implemented anywhere online? The straight forward text field seems to be the norm, but if one has vast amounts of similar data searchable under different criteria, it doesn't quite work!

For example...

St. Marys youth club London
St. Marys bingo club Dublin
St. Marys Judo club Los Angeles
St. Marys Swimming club Paris

If there were 100's of St. Marys clubs around the world, wouldn't be better to be able to split the data by location, or am I completely mistaken???

Anyway thanks again!

cheers! Dec

Yes, so just split it by location, add a country and city column to your database alongwith the place of the location
Click Upvote