2

Why is this wrong?

<table>
  <form>
    <tr><td>something something</td/>
  </form>
</table>

I'm talking about position of form tags inside table tags.

Ales
  • 527
  • 2
  • 8
  • 24

3 Answers3

5

From the DTD:

<!ELEMENT TABLE - -
     (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)>
<!ELEMENT CAPTION  - - (%inline;)*     -- table caption -->
<!ELEMENT THEAD    - O (TR)+           -- table header -->
<!ELEMENT TFOOT    - O (TR)+           -- table footer -->
<!ELEMENT TBODY    O O (TR)+           -- table body -->
<!ELEMENT COLGROUP - O (COL)*          -- table column group -->
<!ELEMENT COL      - O EMPTY           -- table column -->
<!ELEMENT TR       - O (TH|TD)+        -- table row -->
<!ELEMENT (TH|TD)  - O (%flow;)*       -- table header cell, table data cell-->

These are the only elements you can have inside a table element (in HTML 4 in this case, but you check the same kind of document for other versions, and it's not changed much).


On the other hand, a form element can contain any other block-level element (except other forms):

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

And the td element can contain any "flow" element (as seen in the first code block), and "flow" include block level elements:

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

So you can put your <form> tags either around the entire table or inside one table cell.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
2

Only the elements CAPTION, COL, COLGROUP, THEAD, TFOOT and TBODY are allowed as child elements of the TABLE element. See The TABLE element in the HTML specification.

Oswald
  • 31,254
  • 3
  • 43
  • 68
1

Because you can only put <form> tags inside <td> or outside <table>, according to the standards.

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
Ruel
  • 15,438
  • 7
  • 38
  • 49