HighDots Forums  

Span with table elements inside table

Javascript JavaScript language (comp.lang.javascript)


Discuss Span with table elements inside table in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Falc2199
 
Posts: n/a

Default Span with table elements inside table - 06-08-2004 , 11:58 AM






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.getElementById(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=repeatQuestion(divHtml,divId)>

</table>

Thanks in advance,
Jehan

Reply With Quote
  #2  
Old   
Randy Webb
 
Posts: n/a

Default Re: Span with table elements inside table - 06-08-2004 , 12:12 PM






Falc2199 wrote:
Quote:
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.getElementById(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=repeatQuestion(divHtml,divId)

/table
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.javascript FAQ - http://jibbering.com/faq/


Reply With Quote
  #3  
Old   
Ivo
 
Posts: n/a

Default Re: Span with table elements inside table - 06-08-2004 , 12:19 PM



"Falc2199" wrote
Quote:
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.

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




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.