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

difficulty in retrieving value of select/pull-down menu. 1

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
US
hi.
if have this asp page that displays 8 lines of values in a form with a pull-down menu. it's done by a loop and the pull-down menus on the source end up having the same name.
here's the code:
Code:
<form name="Form1" method="post">

<% for i = 1 to 8 %> 
     <INPUT type="text" NAME="itmnbr" size=20> 
     <INPUT type="text" NAME="itmdesc" size=50> 
     <INPUT type="text" NAME="itmprice" size=20> 
     <SELECT name="itmcod" SIZE="1">
          <OPTION value="Select Code">Select Code</option> 
          <OPTION value="111">111</option>    
          <OPTION value="222">222</option>    
          <OPTION value="333">333</option>   
     </SELECT>
     <br />  
<% next %>
</form>
when i try to display the value of itmcod, i'm getting an error.
Error: 'Form1.itmcod.options' is null or not an object
the javascript code looks like this:
Code:
var item_code = Form1.itmcod.options[Form1.itmcod.selectedIndex].text; 
alert (item_code);
however, if i take this pull-down menu out of the loop and put it as single item, it works.
any ideas?
thanks.



 
thanks, billy ray.
how would i treat "itmcod" as a collection please?
can you explain?
thanks.
 
Like so:

Code:
<html>
<head>

	<script type="text/javascript">

		function showThem() {
			var frm = document.forms['theForm'].elements;

			var selObjs = frm['theSelect'];
			for (var loop=0; loop<selObjs.length; loop++) {
				var selectedItem = selObjs[loop].selectedIndex;
				alert('Select element ' + (loop+1) + ' has item ' + selectedItem + ' selected');
			}
		}

	</script>

</head>

<body>
	<form name="theForm">
		<select name="theSelect">
			<option value="1">Item 1</option>
			<option value="2">Item 2</option>
			<option value="3">Item 3</option>
		</select>

		<br />

		<select name="theSelect">
			<option value="1">Item 1</option>
			<option value="2">Item 2</option>
			<option value="3">Item 3</option>
		</select>

		<br />

		<select name="theSelect">
			<option value="1">Item 1</option>
			<option value="2">Item 2</option>
			<option value="3">Item 3</option>
		</select>

		<br />

		<input type="button" value="Show selected options" onclick="showThem();">
	</form>
</body>
</html>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
billy ray,
thanks much. that worked ok. however, is it possible to get the text of the selected item rather than the index?
thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top