473,473 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problems using non-table tags in table.

Hi there.

I'm basically trying to expand a form within a table dynamically.

To this end i've declared a placeholder within my table which i want to
fill out using a javascript.

eg.
<div id=some_section_of_my_page>

<table>
....some rows...
<div id=placeholder></div>
</table>

</div>

When I look at the page source, all is well. However, when I get my
javascript to get the innerHTML of some_section_of_my_page, I see
something like this.

<div id=placeholder></div>
<table>
....some rows...
</table>

unhelpfully moving my placeholder outside of the table.

This works on IE but fails with Firefox/Mozilla.

Any ideas? work arounds? Is this a problem with the DOM or the
function innerHTML?

Thanks in advance.

Tim

Jul 23 '05 #1
6 1246
On 6 Dec 2004 08:11:15 -0800, <t.********@signal.qinetiq.com> wrote:

[snip]
<table>
...some rows...
<div id=placeholder></div>
</table>
[snip]
Any ideas? work arounds? Is this a problem with the DOM or the
function innerHTML?


Neither. It's a problem with your mark-up: it's invalid. The contents of
certain elements are restricted to a specific subset. For example, lists
(OL/UL) may only contain items (LI), and SELECT elements may only contain
OPTION and OPTGROUP elements. The same is true for TABLEs.

The valid elements are defined in the DTD that you're using with your
document. For instance,
<URL:http://www.w3.org/TR/html4/struct/tables.html#h-11.2.1>. Notice the
line

<!ELEMENT TABLE - -
(CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>

The elements in brackets show what a TABLE may contain as its immediate
children. The comma separation means, "in this order". So, an optional
CAPTION (denoted by ?), followed by either zero or more COL elements, or
zero or more COLGROUP elements, followed by an optional THEAD, followed by
an optional TFOOT, followed by at least one TBODY.

If you managed to follow that, you're probably wondering: "Well, what
about TR? Can't I include them directly? Most people do." The answer to
that is yes. If you don't explictly add a TBODY element, the browser will
do it for you.

So what does that all mean? The TBODY element - usually used to group rows
- will probably suffice for your placeholder. Your existing HTML will
become

<table>
<tbody>
<!-- original set of rows -->
</tbody>

<tbody id="placeholder">
<!-- your placeholder -->
</tbody>
</table>

This type of thing is why this group constant recommends that HTML should
be validated (use <URL:http://validator.w3.org/>) before it is scripted.
Invalid HTML can lead to unexpected behaviour, just as you've found here.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Ivo
<t.********@signal.qinetiq.com> asks

I'm basically trying to expand a form within a table dynamically.

To this end i've declared a placeholder within my table which i want to
fill out using a javascript.

eg.
<div id=some_section_of_my_page>

<table>
...some rows...
<div id=placeholder></div>
</table>

</div>

When I look at the page source, all is well. However, when I get my
javascript to get the innerHTML of some_section_of_my_page, I see
something like this.

<div id=placeholder></div>
<table>
...some rows...
</table>


Tables can only contain THEAD, TBODY, TFOOT and TR elements (in fact, only
the first three: if the browser finds only TR elements, a TBODY is
automaticaly created). And TR elements can only contain TD elements. Inside
such TD element freedom is regained and you can place virtually any element
you wish, including whole new tables.

I would think that in your current situation, replacing the placeholder DIV
with a placeholder TD (inside a proper TR) solves the problem.

--
Ivo

Jul 23 '05 #3
Yes, thankyou, sorry to waste your time. Was just difficult to know
what to search for!

Thanks again.

Tim

Jul 23 '05 #4
Yes, thankyou, sorry to waste your time. Was just difficult to know
what to search for!

Thanks again.

Tim

Jul 23 '05 #5
Yes, thankyou, sorry to waste your time. Was just difficult to know
what to search for!

Thanks again.

Tim

Jul 23 '05 #6
Ivo wrote:
[...]
I would think that in your current situation, replacing the placeholder DIV
with a placeholder TD (inside a proper TR) solves the problem.


Depending on what the OP is trying to add to the table. If it is just
adding form elements (or entire tables) inside TDs using innerHTML,
then do what Ivo says.

However, it may also be useful to create entire rows, in which case
using DOM createElement methods would be best and the placeholder id
might be best on a row.

Just a suggestion. ;-)

--
Rob
Jul 23 '05 #7

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

Similar topics

1
by: Irmen de Jong | last post by:
Hi I'm trying to create e-mail content using the email.MIMEText module. It basically works, until I tried to send mail in non-ascii format. What I did, to test both iso-8859-15 and UTF-8...
32
by: jp29 | last post by:
My take on problems composing, serving and rendering XHTML documents/web pages: 1. Typical conscientious web authors are producing XHTML documents (Web pages) that feature valid Markup and with...
3
by: Scott | last post by:
Hello, we are having problems displaying non-aspx files (images, style sheets) since we have upgraded to the 1.1 framework when using a cookieless session (sessionID in the url). Check out...
12
by: Brad | last post by:
Does anyone have any other solutions to the Firefox rendering problems with ASP.NET? I've tried the <browsercaps> web.config trick. It didn't work. Am I overlooking something else? Thanks!
9
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links....
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.