Multiple tables sharing same cell IDs - only update one

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phub11
    New Member
    • Feb 2008
    • 127

    Multiple tables sharing same cell IDs - only update one

    Hi all,

    Could someone please tell (remind) me how I can use "document.getEl ementById('cell ID').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!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    an ID must not occur more than once. (it's how IDs are defined). otherwise use classes or names.
    Code:
    document.getElementsByName([I]__NAME__[/I])[0]; // first element with a given name

    Comment

    • phub11
      New Member
      • Feb 2008
      • 127

      #3
      Thanks for the reply!

      So even if I have unique IDs for each table, the cell IDs for both tables cannot be duplicated? Bah!!!!

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        it is not 'Bah!!!!' :) ... in case it wouldn't be as it is how should the dom parser find an element by id with:

        [CODE=javascript]document.getEle mentById('id');[/CODE]
        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

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          Originally posted by gits
          ... an id currently has to be unique in one document ...
          I hope that's not gonna changing ever…

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            may be you could sometimes use:

            [CODE=javascript]myNode.getEleme ntById('myId');[/CODE]

            :) but i know what you mean and i'm with you :)

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by phub11
              So even if I have unique IDs for each table, the cell IDs for both tables cannot be duplicated? Bah!!!!
              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).

              Comment

              • phub11
                New Member
                • Feb 2008
                • 127

                #8
                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!

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Well, they wouldn't be duplicates then, they'd be unique which of course solves the problem.

                  Comment

                  Working...