"Tom Fitzgibbon" <tk****@hotmail.com> wrote in message
news:bq**********@reader2.panix.com...
Stupid question:
How do I loop through many text boxes on a page and get values for each box
and put into an array?
For example document.CreateEvent.test1.value will not take an array value
for the object name. Tried to figure out if associative arrays might help
but failed miserably. Obviously I can name the text boxes anything, but
can't get the values out.
Thanks for the help -
Tom
Tested on IE5+, Mozilla 1.4 - just call the storeTextBoxes() function where ever
you need it
<html>
<head>
<title>Count Textboxes</title>
<script type="text/javascript">
function storeTextboxes() {
oTextBoxes = new Array(); // to store the textbox objects
oInputs = document.getElementsByTagName( 'input' ) // store collection of all
<input/> elements
for ( i = 0; i < oInputs.length; i++ ) { // loop through and find <input
type="text"/>
if ( oInputs[i].type == 'text' ) {
oTextBoxes.push( oInputs[i] ); // found one - store it in the oTextBoxes
array
}
}
msg = "Found " + oTextBoxes.length + " text boxes";
for ( i = 0; i < oTextBoxes.length; i++ ) { // Loop through the stored
textboxes and output the value
msg += "\nTextbox #" + ( i + 1 ) + " value = " + oTextBoxes[i].value
}
alert( msg );
}
</script>
</head>
<body>
<p><input type="text" name="ele1" size="30"></p>
<p><input type="text" name="ele2" size="30"></p>
<p><input type="text" name="ele3" size="30"></p>
<p><input type="text" name="ele4" size="30"></p>
<p><input type="text" name="ele5" size="30"></p>
<p><input type="button" value="go" onClick="storeTextboxes()"></p>
</body>
</html>