faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

16 of 18 people (89%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I find that which option is clicked in the Select element ?

Sep 22nd, 2001 12:12
Jeff Globe, M Asim,


with ie4+ use this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
 <title></title>
 <script language="JavaScript1.2">
  function getValue(oSelect){
    var sValue = oSelect.options(oSelect.selectedIndex).value
    var sText = oSelect.options(oSelect.selectedIndex).text
    alert(sValue + " : " + sText)
  }
 </script>
</head>
<body>
<select id="selectBox" size="10" onChange="getValue(this)">
	<option value="1">Value 1</option>
	<option value="2">Value 2</option>
	<option value="3">Value 3</option>
	<option value="4">Value 4</option>
	<option value="5">Value 5</option>
	<option value="6">Value 6</option>
	<option value="7">Value 7</option>
	<option value="8">Value 8</option>
	<option value="9">Value 9</option>
	<option value="10">Value 10</option>
</select>
</body>
</html>