473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

loop through text object values in DOM?

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
2 13306
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
6
by: Svein Erik | last post by:
C# asp.net 2.0. I'm creating an online survey. I'm making a string array that's holding the variables of the answers made in the radiobuttonlists that i create manually. I need to make a method...
2
by: fniles | last post by:
I am using .Net 2003 and querying a SQL Server 2000 database. I read the database in a loop, but on every iteration I set the SQLCommand to new, set it, execute it, dispose and set it to nothing....
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
2
by: rn5a | last post by:
In a ASP applicatiuon, the FOrm has a textbox & a select list where the admin can select multiple options. Basically the admin has to enter the name of a new coach in the textbox & select the...
1
by: redgrL86 | last post by:
Hi, I am working on an XSL stylesheet and I have a loop within a loop where I need to compare element values from the inside loop to values from the outer loop (see bolded line in XSL below). The...
10
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.