Get Selected value from dropdown using JavaScript

The Solution to Get Selected value from dropdown using JavaScript is


Maybe it's the comma in your if condition.

function answers() {
var answer=document.getElementById("mySelect");
 if(answer[answer.selectedIndex].value == "To measure time.") {
  alert("That's correct!"); 
 }
}

You can also write it like this.

function answers(){
 document.getElementById("mySelect").value!="To measure time."||(alert('That's correct!'))
}

~ Answered on 2013-09-17 10:10:31


Most Viewed Questions: