<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded',function() {
var colorsSelect = document.getElementById("colors");
var profilesSelect = document.getElementById("profiles");
var colorOptions = {
1: "Wybierz kolor",
2: "Biały 9010",
3: "Złoty Dąb",
4: "Orzech",
5: "Kingchester",
6: "Anracyt 7016",
7: "Deep Mat RAL 7016"
};
var colorSelectMapping = {
1: [1, 2, 3],
2: [1, 2, 3, 4],
3: [1, 4, 5],
4: [1, 2, 7],
5: [1, 2, 6],
6: [1, 3, 4, 5, 6],
7: [1, 2, 3, 4]
};
var colorUpdateList = function (profileNumber) {
while (colorsSelect.options.length) {
colorsSelect.remove(0);
};
var options = filterColorOptions(profileNumber);
for (var option in options) {
var elem = document.createElement("option");
elem.text = colorOptions[option];
elem.className = "colorStandard";
colorsSelect.options.add(elem, option);
};
};
var filterColorOptions = function (profileNumber) {
var results = {};
var optionNumbers = colorSelectMapping[profileNumber];
optionNumbers.forEach(function (number) {
results[number] = colorOptions[number];
});
return results;
};
var profilowanieChangeEvent = function (event) {
var selectedIndex = event.target.selectedIndex;
var selectedOption = event.target.options[selectedIndex].value;
colorUpdateList(selectedOption);
};
profilesSelect.onchange = profilowanieChangeEvent;
colorUpdateList(1);
},false);
</script>
</head>
<body>
<select id="profiles">
<option class="profilowanie" value="1" >Profilowanie wąskie woodgrain</option>
<option class="profilowanie" value="2">Profilowanie szerokie woodgrain</option>
<option class="profilowanie" value="3">Bez profilowań gładki</option>
<option class="profilowanie" value="4">Mikroprofil</option>
<option class="profilowanie" value="5">Kaseton woodgrain</option>
<option class="profilowanie" value="6">Profilowanie wąskie gładkie</option>
<option class="profilowanie" value="7">Profilowanie szerokie gładkie</option>
</select><br>
<select id="colors">
<option class="colorStandard" value="1">Wybierz kolor</option>
</select><br>
</body>
</html>
Rzuć okiem na to.
Oczywiście wartości, które będą w drugim select'ie są przykładowe, ustaw po swojemu zależności pomiędzy 1 selectem a drugim.