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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get value from select field 1

Status
Not open for further replies.

csphard

Programmer
Joined
Apr 5, 2002
Messages
194
Location
US
The following code returns undefinded. How do I get the value for the selected option.

Thanks

<html>

<head>
<title>New Page 10</title>
<script Language="JavaScript"><!--
function checkData()
{

var myTest = me.D1.selectedIndex.value;
alert(myTest);
}
</script>

</head>

<body>

<form method="POST" name="me">
<select size="1" name="D1" onChange="checkData()">
<option value="99">Default</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>
 
selectedIndex, when used correctly, returns the index (number) of the space in the options collection in which the selected option resides.

Here's what you want to use:

me.D1.options[me.D1.selectedIndex].value

I think that's it. Try the following if not:

me.D1.options[me.D1.options.selectedIndex].value

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
thanks that worked. I appreciate your help

Howard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top