VampireFang,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
function generateOptions() {
return {
"AUDI": {
"80": {
url: "p1.html"
},
"100": {
url: "p1.html"
}
},
"BMW": {
"3 series": {
url: "p1.html"
},
"5 series": {
url: "p1.html"
}
}
};
}
const elem = document.querySelector(".chained-selects");
const selects = Array.from(elem.querySelectorAll("select"));
const getOptions = (obj, path = []) => Object.keys(path.reduce((obj, key) => obj[key], obj));
const createOptions = (target, options) => target.append(...options.map(i => new Option(i, i)));
let options = getOptions(generateOptions());
let target = selects[0];
createOptions(target, options);
const change = ({
target
}) => {
let disabled = false,
path = [],
last;
for (let select of selects) {
let value = select.value;
select.disabled = disabled;
if (disabled) select.options.length = 1;
if (target === select) {
last = true;
} else if (!disabled && last) {
select.options.length = 1;
let options = getOptions(generateOptions(), path);
createOptions(select, options);
};
if (select.selectedIndex === 0) disabled = true;
else path.push(value);
}
}
elem.addEventListener("change", change);
elem.querySelector("button").addEventListener("click", () => {
let obj = generateOptions();
for (let {value} of selects) {
if (value in obj) obj = obj[value];
else {
value = Object.keys(obj)[0];
obj = obj[value];
}
}
location.href = obj.url
});
})
</script>
</head>
<body>
<div class="chained-selects">
<select class="app-select form-control">
<option selected>Выберите марку</option>
</select>
<select class="app-select form-control" disabled>
<option selected>Выберите модель</option>
</select>
<button>Найти</button>
</div>
</body>
</html>