views:

143

answers:

1

I got to have a tag inside a table because PHP writes a code there that adds stuff to an earlier created Javascript array. However, I get a validation error (4.01 strict).

Is there any way I can do this or is it simply forbidden to keep a script like this:

<TABLE>
    <TR>
      <SCRIPT></SCRIPT>
        <TD>
        </TD>
    </TR>
</TABLE>

(is this better maybe?):

<TABLE>
    <TR>
        <TD>
         <SCRIPT></SCRIPT>
        </TD>
    </TR>
</TABLE>

Change doctype? What do you think?

+14  A: 

SCRIPT is not allowed in TR as the content model of TR is defined as (TH|TD)+:

<!ELEMENT TR       - O (TH|TD)+        -- table row -->

That means one or more elements of TH or TD.

But SCRIPT is allowed in TD. See the definition of TD:

<!ELEMENT (TH|TD)  - O (%flow;)*       -- table header cell, table data cell-->

Where the parameter entity flow is defined as:

<!ENTITY % flow "%block; | %inline;">

And inline is defined as:

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

And special is define as:

<!ENTITY % special
   "A | IMG | OBJECT | BR | SCRIPT | MAP | Q | SUB | SUP | SPAN | BDO">
Gumbo
Thanks, it's allowed in the second way then but not the first way between <TR> and <TD>?? I'll make sure to have a look again at the HTML TD and SCRIPT spec.
fast-reflexes
Actually, the OP asks about script as child of a `tr`.
Boldewyn
Sorry sorry.. I missed part of your explanation.. I get it all.. thanks Gumbo!!!
fast-reflexes
@fast-reflexes: Added an explanation for `TR`.
Gumbo
Thanks again! Validates perfectly now!
fast-reflexes