I have a code like this:
<label>Brand</label></br>
<select name="brand" id="brand" onChange="changecat(this.value);">
<option value="" selected>Select Brand</option>
<option value="A">AMD</option>
<option value="B">Intel</option>
</select></br></br>
<label>Socket</label></br>
<select name="category" id="category" onchange="showProcessor()">
<option value="" disabled selected>Select Socket</option>
</select>
var brandByCategory = {
A: ["AM4", "AM3", "AM2"],
B: ["LGA 1151", "LGA 1151v2", "LGA 1150"]
}
function changecat(value) {
if (value.length == 0)
document.getElementById("category").innerHTML = "<option>Select Socket</option>";
else {
var catOptions = "";
for (categoryId in brandByCategory[value]) {
catOptions += "<option>" + brandByCategory[value][categoryId] + "</option>";
}
document.getElementById("category").innerHTML = catOptions;
}
}
If the brand option is selected, then it will populate the socket drop-down, and it works, but the socket drop-down option doesn't have a value, i have to give a value to it, because i wanna fetch a data from the database which needs the value of the brand. How to add value in the second drop-down?