By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

loop through text object values in DOM?

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"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>
Jul 20 '05 #2

P: n/a
Thanks - works great
-Tom

"DB McGee" <no*****@noreply.com> wrote in message
news:F3********************@twister01.bloor.is.net .cable.rogers.com...
"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>

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.