Possible Duplicate:
How to get the text of the selected option of a select using jquery?
I have the following script:
<select id = "people">
<option value = "0">Choose</option>
<option value = "1">John</option>
<option value = "2">David</option>
</select>
How Can I use jQuery to detect the value of the option that is currently selected?
i.e. (pseudo-ish code)
if(people.option.text == "Choose"){
//Alert - Please make a selection
}else{
//Valid - do something
}
EDIT: code not working
echo("<script>");
echo("$(document).ready(function(){");
echo("$(\"#go\").click(function(e){");
echo("var selText = $(\"#people option:selected\").text();");
echo("if(selText == \"Choose\"){");
echo("}else{");
echo("window.location.href = \"viewprofile.php\";");
echo("}");
echo("});");
echo("});");
echo("</script>");
It constantly triggers the else statement and navigates away...
EDIT: Got it working -> changed .text() and val()