W
WJ
I have a snippet of sample code. It walks the DOM to get the value of a
select box.
<html>
<head>
<script language="javascript">
function doIt()
{ alert (document.testForm.Items.value);}
</script>
</head>
<body>
<form name="testForm">
<table>
<tr><td>
<select name="Items">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td></tr>
<tr><td>
<input type="button" name="submit" value="Submit!" onclick="javascript:
doIt();">
</td></tr>
</form>
</body>
Runs fine. However, if I change the name of the select box from Items to
Items[0], I get errors:
<html>
<head>
<script language="javascript">
function doIt()
{ alert (document.testForm.Items[0].value);}
</script>
</head>
<body>
<form name="testForm">
<table>
<tr><td>
<select name="Items[0]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td></tr>
<tr><td>
<input type="button" name="submit" value="Submit!" onclick="javascript:
doIt();">
</td></tr>
</form>
</body>
Now, I know the obvious thing is to not use [0]. The reason this is there
is there are more than one of these, several in fact.
This code is generated by jsp, so I really have to leave the array item in
there, or else re-do the entire module. So if I can pull
the values out like this, it would be the best.
Thanks!
select box.
<html>
<head>
<script language="javascript">
function doIt()
{ alert (document.testForm.Items.value);}
</script>
</head>
<body>
<form name="testForm">
<table>
<tr><td>
<select name="Items">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td></tr>
<tr><td>
<input type="button" name="submit" value="Submit!" onclick="javascript:
doIt();">
</td></tr>
</form>
</body>
Runs fine. However, if I change the name of the select box from Items to
Items[0], I get errors:
<html>
<head>
<script language="javascript">
function doIt()
{ alert (document.testForm.Items[0].value);}
</script>
</head>
<body>
<form name="testForm">
<table>
<tr><td>
<select name="Items[0]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td></tr>
<tr><td>
<input type="button" name="submit" value="Submit!" onclick="javascript:
doIt();">
</td></tr>
</form>
</body>
Now, I know the obvious thing is to not use [0]. The reason this is there
is there are more than one of these, several in fact.
This code is generated by jsp, so I really have to leave the array item in
there, or else re-do the entire module. So if I can pull
the values out like this, it would be the best.
Thanks!