I have a selection box with three different options (4 really with the blank one) and after I click a button I need an alert box to display a message. Here's some code.
HTML:
<select id="item1" name="Item 1">
<option></option>
<option value="1">Camera</option>
<option value="2">Microphone</option>
<option value="3">Tripod</option>
</select>
<button onclick="message()">Go!</button>
Javascript:
<SCRIPT language = javascript>
function message() {
var s = document.getElementById('item1');
var item1 = s.options[s.selectedIndex].value;
if (item1 = 1) {
alert("it equals camera")
}
else if (item1 = 2) {
alert("it equals microphone")
}
else if (item1 = 3) {
alert("it equals tripod")
}
}
</SCRIPT>
Every time I click the button the alert box says "it equals camera". I could select Microphone and click the button and it would still say that.
If I put
alert(item1)
in the function it displays 1, 2, or 3. So I'm assuming it's something with the if..else.. statements.