473,702 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing table markup with script

I have some markup like the following:

<form>
<table>
<script>
<!-- Write the table markup //-->
</script>
</table>
<form>

The script draws the guts of the table as it is being rendered. This
works just fine, except that HTML 4.01 strict (to which I'd like to
conform) requires <script> tags to be children of either <head> or
<body>. I'd like to find a good way to get the <script> where the
standard wants it. My first idea is to draw the table with script
using innerHTML after the table has rendered, but the table in
question is decently sized, which makes me suspect that a browser
would have some performance issues with rendering it after the fact.
Is there a better way to accomplish what I want?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
6 1790
On Fri, 1 Oct 2004 19:42:35 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.c yberspace.org> wrote:

[snip]
The script draws the guts of the table as it is being rendered.
I'll assume that using server-side scripting is not an option.
This works just fine, except that HTML 4.01 strict (to which I'd like to
conform) requires <script> tags to be children of either <head> or
<body>.
That's not quite true. SCRIPT elements can be placed in the HEAD element,
and anywhere else that accepts "special" or "inline" elements. That
includes many places, but it does not include SCRIPTs as direct children
of TABLEs. In fact, only a few elements can be direct children of any
TABLE element.

[snip]
Is there a better way to accomplish what I want?


Well, what precisely do you want? Are you writing the entire table, or
just a subsection of it? If it's the latter, are we talking an entire
table section, a couple of rows, or just one or two cells?

If you're writing the entire table, write the TABLE tags with the script,
too. If it is just a few parts, it would be best to add them after the
table has been rendered.

By the way, you can only write to the innerHTML property of TD elements.
All other table components (expect CAPTION) are read-only. However, you
can use the W3C DOM to add, remove and modify table sections and rows.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Michael Winter <M.******@bluey onder.co.invali d> spoke thus:
I'll assume that using server-side scripting is not an option.
Correct.
That's not quite true. SCRIPT elements can be placed in the HEAD element,
and anywhere else that accepts "special" or "inline" elements. That
includes many places, but it does not include SCRIPTs as direct children
of TABLEs. In fact, only a few elements can be direct children of any
TABLE element.
The W3C site http://www.w3.org/TR/html4/interact/....html#h-18.2.1
suggests, at least to me, that <head> and <body> are the only
permissible parents of <script>.
Well, what precisely do you want? Are you writing the entire table, or
just a subsection of it? If it's the latter, are we talking an entire
table section, a couple of rows, or just one or two cells?
It's the entire table, a typical size of which is 6 rows by 10
columns. It seems to my uneducated thinking that that's a significant
amount of work for a browser to insert using innerHTML.
If you're writing the entire table, write the TABLE tags with the script,
too. If it is just a few parts, it would be best to add them after the
table has been rendered.
Well, currently I *am* writing the table with script, but if my
interpretation of the information I linked to above is correct, I
won't be able to do so and conform to the HTML 4.01 standard.
By the way, you can only write to the innerHTML property of TD elements.
All other table components (expect CAPTION) are read-only. However, you
can use the W3C DOM to add, remove and modify table sections and rows.


But I could insert an entire table in a <td>, correct? It does happen
that in the real markup the table in question is the child of a <td>
element. Perhaps that option is at least possible...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #3
Christopher Benson-Manica wrote:
The W3C site http://www.w3.org/TR/html4/interact/....html#h-18.2.1
suggests, at least to me, that <head> and <body> are the only
permissible parents of <script>.


"in" means "descendent of" not "child of"

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #4
On Fri, 1 Oct 2004 20:05:08 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.c yberspace.org> wrote:

[snip]
The W3C site http://www.w3.org/TR/html4/interact/....html#h-18.2.1
suggests, at least to me, that <head> and <body> are the only
permissible parents of <script>.
True, the text of the specification states that SCRIPT elements may appear
in the HEAD and BODY elements, but it doesn't say that is the only
location. The DTD is more specific:

<!ENTITY % special
"A | IMG | OBJECT | BR | SCRIPT | MAP | Q | SUB | SUP | SPAN | BDO">

marks the SCRIPT element as a special entity, which in turn,

<!ENTITY % inline
"#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">

is an inline element.
<!ELEMENT HEAD O O (%head.content; ) +(%head.misc;)>

and

<!ENTITY % head.misc "SCRIPT|STYLE|M ETA|LINK|OBJECT ">

declare that the SCRIPT element may occur in the HEAD element any number
of times.

Furthermore,

<!ELEMENT BODY O O (%block;|SCRIPT )+ +(INS|DEL)>

makes a special exception for SCRIPT, which unlike other inline elements,
may appear as a direct child of the BODY element.

So far, this agrees with your assessment, but:

<!ELEMENT P - O (%inline;)*>

and

<!ELEMENT A - - (%inline;)* -(A)>

do not. Here, both P and A elements state that they may contain any inline
elements. If SCRIPTs were disallowed, a similar entry would occur like
"-(A)" to explicitly disallow them. The vast majority of non-empty
elements are the same. The only exceptions are elements like lists,
tables, SELECTs, and similar that define precisely what they can contain.

I hope that's a clear enough case. :)
It's the entire table, a typical size of which is 6 rows by 10 columns.
It seems to my uneducated thinking that that's a significant amount of
work for a browser to insert using innerHTML.
I don't think so. Richard Cornford (<URL:http://www.litotes.dem on.co.uk/>)
has written a table sorter that obviously requires the movement of
potentially all the rows in a table. His demo initially uses 200 rows and
the operation occurs very quickly. What you're proposing isn't that taxing
for modern processors. Can't say I know when performance would suffer,
though.

[snip]
Well, currently I *am* writing the table with script, but if my
interpretation of the information I linked to above is correct, I won't
be able to do so and conform to the HTML 4.01 standard.
You can, but the SCRIPT element must be placed in an element that allows
inline elements. P, TD, DIV, and numerous others all qualify.

[snip]
But I could insert an entire table [using innerHTML] in a <td>,
correct? It does happen that in the real markup the table in question
is the child of a <td> element. Perhaps that option is at least
possible...


You could. It would probably be more efficient than using the W3C DOM,
too, unless the rows were identical and you could just clone them.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
David Dorward <do*****@yahoo. com> spoke thus:
"in" means "descendent of" not "child of"


Oh, now I see. So Michael's original suggestion was spot on. Thanks
to both of you.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #6
Michael Winter <M.******@bluey onder.co.invali d> spoke thus:
I hope that's a clear enough case. :)
Yes, I did understand it... maybe next time I will look at the DTD
myself before making guesses. ;)
You could. It would probably be more efficient than using the W3C DOM,
too, unless the rows were identical and you could just clone them.


Yes, now I see, and I have done so. Thank you.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #7

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

Similar topics

8
23993
by: F. Da Costa | last post by:
Following is a snippet of html in which I hide a whole table and try to hide a single row. Here is my question (plz don't chew my head off if its css related instead): Why does the divTable <div> Hide/Show work but not the divRow version? What I'm trying to do here is simultaneously hide 1 or more rows (possibly with nested divs as well). This would allow for an elegant an well performing base for an html base treetable (but I guess...
61
24480
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will 'stretch'</td> <td valign="top" width="300">some data that won't 'stetch'</td> </tr> </table>
5
3899
by: Greg N. | last post by:
Hi folks, I have a table cell with a background image, something like <td background=landscape.jpg height=200></td> The sole purpose of this code is to display the image inside that table cell. It displays just as much of the image as the current cell width allows. The actual cell width is determined by other cells in the same table column and by the current browser window width.
385
17187
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are
17
7680
by: Eric Lindsay | last post by:
Is learning to write CSS a better use of time than finding and using a package that produces complete web pages? I've moved to a new platform (Macintosh), taking with me about 400 personal web pages, some dating back so far I probably wrote them in vi. About 4 years ago (thanks in part to hints found in this group) I converted about 80 pages to CSS, and was fairly happy with the result, plain though they are. Since then I've forgotten...
28
18526
by: Giggle Girl | last post by:
Can someone show me how to insert a row at any given row index of an already created table? It only has to work in IE6 (used on intranet at work). Specifically, if a table is 20 rows in total (thought his will vary), and someone wants to insert a new row at row 5, i need for one row to be added, and each of the rows from 5-20 to be "cloned" to 6-21. The contents of row 5 may vary as well; it is not a straight copy of an exisiting row.
3
1476
by: King Albert | last post by:
Why does the 'insertrow' work in this situation: <html> <script type="text/javascript"> function addRow(tableID) { var tableRef = document.getElementById(tableID); var newRow = tableRef.insertRow(2); var newCell = newRow.insertCell(0); var newText = document.createTextNode('New second cell') newCell.appendChild(newText);
6
7995
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data, call determined functions, and edit the data already present What will you need to use the grid? A table with standard markup and an ID to call the script that will turn the table into a grid Parameters: tabelaID => id of the table that will...
2
1608
by: oldyork90 | last post by:
Is there a way I can time browser drawing/rendering time for a given element. I have a huge table. I have it's name. We'd like to experiment with different combinations to speed things along. Can we capture the time somehow? Thanks
0
8738
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8652
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7829
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5907
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4412
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3104
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 we have to send another system
2
2399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.