Span with table elements inside table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Falc2199

    Span with table elements inside table

    i all,
    I have an HTML table within which I have a span. When the user
    clicks a button I want to update the contents of this span with form
    elements table elements (TR,TD).

    The problem is that if I do not wrap the span tag inside a TR
    and TD, it is not properly placed in the table and the update does not
    work at all. However if I do place the span inside a TR and TD, the TR
    and TD which was supposed to go into the span is not becoming properly
    aligned because now I have nested TR and TDs.

    Anyone have any thougts, here is some sample code....

    function repeatQuestion( divHtml, divId) {


    var elem = document.getEle mentById(divId) ;
    elem.innerHTML = divHtml; // divHtml contains TD and TRs

    }

    <table>

    <span id="divId"></span> // this does not work
    <tr><td><span id="divId"></span></td></tr> // this works but format
    messed up

    <input type=button onClick=repeatQ uestion(divHtml ,divId)>

    </table>

    Thanks in advance,
    Jehan
  • Randy Webb

    #2
    Re: Span with table elements inside table

    Falc2199 wrote:[color=blue]
    > i all,
    > I have an HTML table within which I have a span. When the user
    > clicks a button I want to update the contents of this span with form
    > elements table elements (TR,TD).
    >
    > The problem is that if I do not wrap the span tag inside a TR
    > and TD, it is not properly placed in the table and the update does not
    > work at all. However if I do place the span inside a TR and TD, the TR
    > and TD which was supposed to go into the span is not becoming properly
    > aligned because now I have nested TR and TDs.
    >
    > Anyone have any thougts, here is some sample code....
    >
    > function repeatQuestion( divHtml, divId) {
    >
    >
    > var elem = document.getEle mentById(divId) ;
    > elem.innerHTML = divHtml; // divHtml contains TD and TRs
    >
    > }
    >
    > <table>
    >
    > <span id="divId"></span> // this does not work
    > <tr><td><span id="divId"></span></td></tr> // this works but format
    > messed up
    >
    > <input type=button onClick=repeatQ uestion(divHtml ,divId)>
    >
    > </table>[/color]

    Instead of divHtml containing "TD and TR's", have it contain TABLE, TR
    and TD tags. Then, you are not inserting fragments of tables, but entire
    tables.

    Or, use appendChild to add to an existing table.


    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Ivo

      #3
      Re: Span with table elements inside table

      "Falc2199" wrote[color=blue]
      > I have an HTML table within which I have a span. When the user
      > clicks a button I want to update the contents of this span with form
      > elements table elements (TR,TD).
      >
      > The problem is that if I do not wrap the span tag inside a TR
      > and TD, it is not properly placed in the table and the update does not
      > work at all. However if I do place the span inside a TR and TD, the TR
      > and TD which was supposed to go into the span is not becoming properly
      > aligned because now I have nested TR and TDs.
      >[/color]

      Why do you need that span? Replace the (contents of) the TR's and TD's
      directly.
      The table and its children are very useful elements, but of course you need
      to keep them properly nested. That means a TABLE can only contain TR, TBODY,
      THEAD and TFOOT elements. A TR can only contain TH and TD elements, but
      they can contain all sorts of other elements.
      If that is all right, you can easily make use of the rows and cells
      collections to access and manipulate whatever you like, even without the
      need for unique ID's on each element.
      Ivo


      Comment

      Working...