WSN Knowledge Base
Location Filtering
Location Filtering
By Paul

Suppose you want a series of chained selectors to narrow a search to a particular town. You want the visitor to select a country first, which will populate a states selector with the appropriate states for that country. Next they select a state, which populates a city selector with cities in that state.

Add the following in your advanced search form to accomplish this. Requires version 5.1.17 or newer. Also requires having the postal code range search switch on, and databases loaded for the countries you need in this chained selector. The postal database must have the states in the same format as the articles have (can't abbreviate on one and not on the other).

<IF 0>
<script type="text/javascript">
function statefilter()
{
var thecountry = $("[name=countrysearch]").val();
$.post("{SUBDIRURL}/ajax.php",{ action: 'getstates', country: thecountry },
function(xml)
{
$("[name=statesearch]").html(xml);
});

}
function cityfilter()
{
var thestate = $("[name=statesearch]").val();
var thecountry = $("[name=countrysearch]").val();
$.post("{SUBDIRURL}/ajax.php",{ action: 'getcities', state: thestate, country: thecountry },
function(xml)
{
$("[name=citysearch]").html(xml);
});
}
</script>

<p>Filter to your desired location, starting with the country:</p>
<br />Country:
<input type="hidden" name="countrycondition" value="=" />
<select name="countrysearch" onchange="statefilter()"><option value=""></option>{COUNTRYOPS}</select>
<br />State/Territory:
<input type="hidden" name="statecondition" value="=" />
<select name="statesearch" onchange="cityfilter()"><option value=""></option></select>
<br />City:
<input type="hidden" name="citycondition" value="=" />
<select name="citysearch"><option value=""></option></select>
</IF>

Rating:


0/5 based on 0 votes. The median rating is 0.

Submitted: 12/22/09 (Edited 03/13/10)

Description: Filtering from country to state or province and finally down to city.

Views: 100 views. Averaging 0 views per day.
In the most recent 30 day period, there've been 3 views.

Previous Article | Next Article

Features Showcase Purchase Services Resources Support