Latest Register Log In

+ Advanced Search

Location Filtering

Location Filtering
By
12/22/09 (Edited 03/11/14)

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 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 listings have (can't abbreviate on one and not on the other).

<IF {SWITCH_ZIPRANGE}>
<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>




Description Filtering from country to state or province and finally down to city.
Rating
Views 366 views. Averaging 0 views per day.