JavaScript problem

Associate
Joined
31 Dec 2002
Posts
458
Hi, I am struggling to get the following code to work. I am trying to extract the value from a selected drop down list option item and then using an if statement to compare to a value. I know the two variables get the value ok, as if I use an alert with the variable item in brackets it displays the selected value fine. For some reason I cannot get the if statement to check it. The values in the option items in the list are "1" "2" and "3". "q1" is the id of the select element:

function score()
{
var list = document.getElementById("q1");
var item = list.options[list.selectedIndex].value;

if (item == 2)
{
alert("Correct");
}
else
{
alert("incorrect");
}

}

hope someone can help.
 
Back
Top Bottom