need some help here please ,
Basically what I've at this point is a script a user here shared with me , what it does is that it has created a hidden paragraph and the content displayed on this paragraph is conditioned by the values of 2 dropdowns , it works absolutely fine , there is only one thing though :
for the first < select > I want to use numbers as values : 0 for Audi , 1 for BMW , 2 for Mercedes and so on , but once I replace those values with numbers it doesnt seem to work ,
Please check the code , any help is more than appreciated , really :)
function myFunction() {
let messages = {
AudiBlack: 'Black Audi',
AudiRed: 'Red Audi',
BMWBlack: 'Black BMW',
BMWRed: 'Red BMW',
MercedesBlack: 'Black Mercedes',
MercedesRed: 'Red Mercedes',
VolvoBalck: 'Black Volvo',
VolvoRed: 'Red Volvo'
};
var car = document.getElementById("mySelect").value;
var color = document.getElementById("Variants").value;
document.getElementById("demo").innerHTML = `${messages[car+color]}`;
}
<body>
<p>Select a new car from the list.</p>
<select id="mySelect" onchange="myFunction()">
<option value="Audi">Audi
<option value="BMW">BMW
<option value="Mercedes">Mercedes
<option value="Volvo">Volvo
</select>
<select id="Variants" onchange="myFunction()">
<option value="Black"> Black
<option value="Red">Red
</select>
<p>When you select a new car, a function is triggered which outputs the value of the selected car.</p>
<p id="demo"></p>
</body>