473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
6 1759
On Fri, 1 Oct 2004 19:42:35 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.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.******@blueyonder.co.invalid> 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)cyberspace.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.cyberspace.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|META|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.demon.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)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #6
Michael Winter <M.******@blueyonder.co.invalid> 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)cyberspace.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
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...
61
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...
5
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...
385
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...
17
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...
28
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...
3
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 =...
6
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,...
2
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. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.