i got a form with a select form elements for month.
<select id="month" name="month">
<option value="Jan">Jan</option>
<option value="Feb">Feb</option>
<option>Mar
<option>Apr
<option>May
<option>Jun
<option>Jul
<option>Aug
<option>Sept
<option>Oct
<option>Nov
<option>Dec
</select>
How do i use javascript to get compare the selected value. for example if i select Feb, the javascript will pop up "you selected feb"
var monthSelect = document.getElementById("month")
var opt = monthSelect.options[monthSelect.selectedIndex]
if(opt.text == "Feb")
{
alert("Feb selected")
return false
}
</option>And why not just usedocument.getElementById("month").value...? Also you need to attach an event listener or an attribute event handler<option>is a tag with optional closing tag. It's better if you close, but it's not invalid. Exactly like<li>or<td>element.valuesuggestion. As simple asalert(document.getElementById("month").value+ " selected");