Re: Valid positioning of script elements

I agree.  This seems strange to me as well.  Being able to put script tags in a
table tag allows you to create more dynamic pages.  You can create server side
scripts (using ASP for example) that dynamically fills in a table, but it's
invalid to use client side scripting to accomplish the same thing.  I'm not sure
if this is an issue for the html list or the validator list (so I'll send this
to both).

The following code is invalid, according to the w3 validator.  But I would argue
that it should not be.  Can someone offer an explanation as to why it should be
invalid?
Thanks,
Pete

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
     <title>Test</title>
</head>

<body>

<table>
     <tr>
          <td>1,1</td></tr>
     <script language="Javascript" type="text/javascript">
     var str = "<tr><td>2,1<\/td><\/tr>"
     document.write(str);
     </script>
</table>

</body>
</script>





Clover Andrew <aclover@1VALUE.com> on 06/05/2000 02:44:00 PM

To:   "'www-html@w3.org'" <www-html@w3.org>
cc:    (bcc: Peter Foti)

Subject:  Valid positioning of script elements



I note from the HTML 4.01 DTD and from coming a cropper on the
validator that one may only insert <script>s at block-level,
inline, or in <head>. It is invalid for a script to live in
structural markup such as <table>, <tr>, <dl> and so on.

Is there any particular rationale behind this definition, or is
it simply arbitrary? (It differs from every browser's
implementation of <script>, though of course that on its own
doesn't mean anything.) Is there any chance of a change in the
future?

It would be quite useful to me to be able to, for example,
document.write(some extra table rows), to produce content
that only appears when JavaScript is enabled (with different,
backup behaviour where scripting is not supported, natch).
The alternative is to write <tr> and <td> elements with
block-level <script>s inside them, leaving empty rows
when scripting is unavailable. This does not appeal to
me aesthetically. :-)

--
Andrew Clover
Technical Support
1VALUE.com AG

Received on Monday, 5 June 2000 15:42:05 UTC