Get Selected value from dropdown using JavaScript [duplicate] Get Selected value from dropdown using JavaScript [duplicate] javascript javascript

Get Selected value from dropdown using JavaScript [duplicate]


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!'))}


Try

var e = document.getElementById("mySelect");var selectedOp = e.options[e.selectedIndex].text;


The first thing i noticed is that you have a semi colon just after your closing bracket for your if statement );

You should also try and clean up your if statement by declaring a variable for the answer separately.

function answers() {var select = document.getElementById("mySelect");var answer = select.options[select.selectedIndex].value;    if(answer == "To measure time"){        alert("Thats correct");     }}

http://jsfiddle.net/zpdEp/