[thelist] Help with document.all.item("SomeElement").item(i)
Gregory.John.Toland at census.gov
Gregory.John.Toland at census.gov
Wed Oct 4 10:47:10 CDT 2000
Help please!!!! I can not figure this out. If you run this code only odd item
numbers are shown by the following line:
alert ( document.all.item( "txtTopic" ).item( i ).value );
The length is shown correctly as 10.
The i (index) value progresses correctly from 1, 2, 3, 4, 5,...
But here is what is happening:
alert ( document.all.item( "txtTopic" ).item( 1 ).value ) = 1
alert ( document.all.item( "txtTopic" ).item( 2 ).value ) = 3
alert ( document.all.item( "txtTopic" ).item( 3 ).value ) = 5
alert ( document.all.item( "txtTopic" ).item( 4 ).value ) = 7
alert ( document.all.item( "txtTopic" ).item( 5 ).value ) = 9
alert ( document.all.item( "txtTopic" ).item( 6 ).value ) = ERROR!
How do I access the even numbered OPTION tags??????
P.S. I am using IE 5.01 on WinNTW SP6a
Here is the code (short, simple):
<html>
<head>
<title>Test</title>
</head>
<body>
<script language=JavaScript type=text/javascript>
<!--
function GetTopics()
{
var i = 00;
var nLength;
nLength = document.all.item( "txtTopic" ).length;
alert( nLength );
for ( i = 01; i < nLength; i++ )
{
alert( i );
alert ( document.all.item( "txtTopic" ).item( i ).value );
document.all.item( "txtTopic" ).remove( i );
}
}
//-->
</script>
<form id=frmResults name=frmResults>
<table border=0 cellPadding=3 cellSpacing=0>
<tr>
<td class="EvalFormsBody">Research Area:</td>
<td>
<select id="txtArea" name="txtArea" onChange="GetTopics()"
size="1">
<option value='00' selected>Select an area</option>
<option value='01'>Select another area</option>
</select>
</td>
</tr>
<tr>
<td>Research Topic:</td>
<td>
<select id=txtTopic name=txtTopic size=1>
<option selected value=00>Select a topic</option>
<option value=01>Select 1 topic</option>
<option value=02>Select 2 topic</option>
<option value=03>Select 3 topic</option>
<option value=04>Select 4 topic</option>
<option value=05>Select 5 topic</option>
<option value=06>Select 6 topic</option>
<option value=07>Select 7 topic</option>
<option value=08>Select 8 topic</option>
<option value=09>Select 9 topic</option>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
More information about the thelist
mailing list