469,307 Members | 1,836 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

Multiple tables sharing same cell IDs - only update one

127 100+
Hi all,

Could someone please tell (remind) me how I can use "document.getElementById('cellID').innerHTML" for a specific cell for a specific table, given that two tables share the same cell ID names, but I only want to update one of them.

Thanks!
May 11 '09 #1
8 2598
Dormilich
8,651 Expert Mod 8TB
an ID must not occur more than once. (it's how IDs are defined). otherwise use classes or names.
Expand|Select|Wrap|Line Numbers
  1. document.getElementsByName(__NAME__)[0]; // first element with a given name
May 11 '09 #2
phub11
127 100+
Thanks for the reply!

So even if I have unique IDs for each table, the cell IDs for both tables cannot be duplicated? Bah!!!!
May 11 '09 #3
gits
5,390 Expert Mod 4TB
it is not 'Bah!!!!' :) ... in case it wouldn't be as it is how should the dom parser find an element by id with:

Expand|Select|Wrap|Line Numbers
  1. document.getElementById('id');
the method always returns one node and in case there are nodes with the same id which one should it choose? ... an id currently has to be unique in one document ...

kind regards
May 11 '09 #4
Dormilich
8,651 Expert Mod 8TB
@gits
I hope that's not gonna changing ever…
May 11 '09 #5
gits
5,390 Expert Mod 4TB
may be you could sometimes use:

Expand|Select|Wrap|Line Numbers
  1. myNode.getElementById('myId');
:) but i know what you mean and i'm with you :)
May 12 '09 #6
acoder
16,027 Expert Mod 8TB
@phub11
You should never need to use duplicate IDs. You can always give it IDs such as "c111" where the first 1 can be the table, the second the row and the third the cell (this is based on what I remember you naming your cells from earlier posts).
May 12 '09 #7
phub11
127 100+
Thanks for the replies!

I resorted to "acoder"'s suggestion. I figured that as tables act as parents for their respective cells, it would be logical that prefixing a cell ID with it's parent (table) using document.get would allow duplicate cell IDs. I guess I've quite a bit to learn!
May 12 '09 #8
acoder
16,027 Expert Mod 8TB
Well, they wouldn't be duplicates then, they'd be unique which of course solves the problem.
May 12 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by RJ | last post: by
5 posts views Thread by sds | last post: by
1 post views Thread by Justin | last post: by
8 posts views Thread by Jason L James | last post: by
16 posts views Thread by Randy Harris | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.