I have 2 separate dropdown lists and submit button which takes the visitor to a unique URL based on selections.
I need to get each dropdown to filter each other.
for example: When someone chooses "Volvo" from the first dropdown menu, then the second drop-down menu shows only "Red" & "White" and so on.
HTML
<form>
<select class="homepage-dropdown col-md-6 col-9" id="carbrand">
<option value="volvo">Volvo</option>
<option value="saab" selected="selected">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<br>
<select class="homepage-dropdown col-md-6 col-9" id="carcolor">
<option value="white">White</option>
<option value="black" selected="selected">Black</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
</select>
<br/><br/>
<input id="btnCallURL" type="button" value="بحث">
</form>
Javascript
document.getElementById('btnCallURL').onclick = function() {
var carbrandObj = document.getElementById('carbrand');
var carcolorObj = document.getElementById('carcolor');
var carbrandValue = carbrandObj.options[carbrandObj.selectedIndex].value;
var carColorValue = carcolorObj.options[carcolorObj.selectedIndex].value;
jsCallUrl(carbrandValue, carColorValue);
}
function jsCallUrl(carbrandValue, carColorValue){
var pageUrl = "";
switch (carbrandValue){
case "volvo":
switch (carColorValue){
case "white":
pageUrl = "volvo-white-page-url.php";
break;
case "black":
pageUrl = "volvo-black-page-url.php";
break;
case "red":
pageUrl = "volvo-red-page-url.php";
break;
case "blue":
pageUrl = "volvo-blue-page-url.php";
break;
}
break;
case "saab":
switch (carColorValue){
case "white":
pageUrl = "saab-white-page-url.php";
break;
case "black":
pageUrl = "saab-black-page-url.php";
break;
default:
pageUrl = "saab-othercolor-page-url.php";
break;
}
break;
}
if (pageUrl != ""){
location.href = "https://domain/" + pageUrl;
}
}