Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selected Index problem - testing for value

Status
Not open for further replies.

monkey64

Technical User
Apr 27, 2008
69
GB
I'm trying to output the selected value form a select box and compare it, see code below. If someone selects "Test1", I want the alert box "yes", for every other selection, "no". I'm sure this is simple stuff, but I'm stumped! Can anyone help me?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script language="JavaScript" type="text/javascript">

function showhide() {
	
	var s = document.getElementById("t");
	if(s.options[s.selectedIndex].text = "Test1") {
		alert("yes");
			} else {
				alert ("no");	
				}
}

</script>


</head>

<body>
<select name="ttype" onchange="showhide()" id="t">
<option value="Test1">Test1</option>
<option value="Test2">Test2</option>
</select>
</body>
</html>
 
>I'm sure this is simple stuff,...
Every time I see that, I'll get all excited: that's my level.

"=" is easy assignment
"==" is easy comparison
 
tsji

I was right. It was simple stuff.. Thanks for that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top