473,395 Members | 1,885 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,395 software developers and data experts.

call an ID range

Amy
let say i have an id range Ie. test1, test2, test3 ...

How do i call all of them at a time ? I cant use getElementbyId for
sure ...

Anyone has any clues?

Jul 20 '06 #1
3 1258
Amy said the following on 7/20/2006 2:56 AM:
let say i have an id range Ie. test1, test2, test3 ...

How do i call all of them at a time ? I cant use getElementbyId for
sure ...
Actually, you can. You just set a loop:

for (var i=1;i<4;i++){
thisID = document.getElementById('test' + i)
//do something with thisID
}

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 20 '06 #2
Amy wrote:
let say i have an id range Ie. test1, test2, test3 ...

How do i call all of them at a time ? I cant use getElementbyId for
sure ...
If you know the number of elements, you can always try a for-loop:

for (i = 0; i < MAX; i++) {
e = document.getElementById('test' + i);
if (e == null) continue;
// do something with e
}

Another option is to give every element the same _name_, you can query
those:

// returns array of objects named 'test'.
t = document.getElementsByName('test');

If you know the type of the elements you can query
getElementsByTagName() in the same way as you query the getelements. You
can check with startsWith whether its the right object:

t = document.getElementsByTagName('input');

for (i = 0; i < t.length; i++) {
if (t.id.startsWith('test')) {
// do somethnig
}
}

If all else fails you'll have to walk the DOM tree recusivly, or if you
only target IE, you can use the all[] array to walk through all elements.

Good luck,
Vincent
Jul 20 '06 #3
Amy
cool ..that works
Randy Webb wrote:
Amy said the following on 7/20/2006 2:56 AM:
let say i have an id range Ie. test1, test2, test3 ...

How do i call all of them at a time ? I cant use getElementbyId for
sure ...

Actually, you can. You just set a loop:

for (var i=1;i<4;i++){
thisID = document.getElementById('test' + i)
//do something with thisID
}

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bwooster47 | last post by:
I'm a newcomer to python - what is the best way to convert a list into a function call agruments? For example: list = (2005, 5, 5) date = datetime.date( list ) fails with: TypeError:...
54
by: Neo | last post by:
Hi Folks, I've a simple qestion related to dynamic memory allocation in C here is the code: #include <stdio.h> int main() {
15
by: Anonymousgoogledeja | last post by:
Hi all, since the function atof, atoi, _atoi64, atol returned value are Return Values Each function returns the double, int, __int64 or long value produced by interpreting the input...
2
by: Stefan | last post by:
I have a C-API and need to know how to implement a few function in VB.Net. Who can help to translate this? The functions sends a two-dimensional array to a server and get a changed array back....
8
by: Joachim | last post by:
Hi, I want to try call/run Ms. Word via my VB.Net First I added reference : Microsoft Word 11.0 Object Library. Then I got 2 references in my reference list : Word and Microsoft.Office.Core When...
16
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
1
by: David Abrahams | last post by:
This inaugural Boost conference promises to be the main face-to-face venue for all things Boost, from using libraries to writing them, from evangelizing Boost to deployment within your...
7
by: Laurent Pointal | last post by:
on win32] Given the following: 45 .... (<generator object at 0x00A79788>,) .... File "<stdin>", line 1 SyntaxError: invalid syntax
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
2
by: CStrickland | last post by:
#include <iostream> void Lab11identification() { } int getNumericGrade (int gradeIn) {
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.