Forum Moderators: open
<!DOCTYPE html>
<html>
<head>
<title>Test Menu</title>
<style type="text/css">
.invisible { visibility: hidden; }
</style>
</head>
<body>
<select id="regions">
<option value="">Reset Menu</option>
<option value="1">Region 1</option>
<option value="2">Region 2</option>
<option value="3">Region 3</option>
</select>
<select id="provinces">
<option value="">Reset Menu</option>
<option value="1">Province 1</option>
<option value="2">Province 2</option>
<option value="3">Province 3</option>
</select>
<select id="categories" class="invisible">
<option value="">Reset Menu</option>
<option value="1">Category 1</option>
<option value="2">Category 2</option>
<option value="3">Category 3</option>
</select>
<script type="text/javascript">
(function () {
var regions = document.getElementById('regions'),
provinces = document.getElementById('provinces'),
categories = document.getElementById('categories');
function menuHandler(el) {
if (el.selectedIndex === 0) {
regions.disabled = provinces.disabled = false;
categories.style.visibility = 'hidden';
}
else {
categories.style.visibility = 'visible'
if (el === regions) {
provinces.disabled = true;
}
else if (el === provinces) {
regions.disabled = true;
}
else if (el === categories) {
// do search
if (regions.disabled) {
// province search
alert('province search');
}
else {
// regions search
alert('regions search');
}
}
}
}
regions.onchange = function () {
menuHandler(regions);
};
provinces.onchange = function () {
menuHandler(provinces);
};
categories.onchange = function () {
menuHandler(categories);
};
})();
</script>
</body>
</html>
In this case for my two examples would return
Region 1 + Category 1 = r='1'&c='1'
Province 3 + Category 3 = p='3'&c='3'
Of course I need to replace r/p/c with whatever my software uses for those parameters.
Can I ask, why are the "+" necessary? Why not write r='regions.value'&c='categories.value'?
And finally, I replace "alert('province search')" with what in order for it to execute the url directly?
Oh. I just noticed 1 thing with your URL. You didn't put two trailing ' before the final ;. 1 for the 'http statement and 1 for the ' + categories.value statement. Is that intentional? Or should it be written "'http.....;"?
location = 'http://www.example.com/yourSearchPage.php?r=' +
regions.value +
'&c=' +
categories.value;