willem
willem

Reputation: 27027

Is a <form> valid over a <tr>?

Is the following valid HTML? What I am wondering about specifically is the location of the <form> tag.

<table>
    <form>
        <tr>
            <td>
                <input id="txt" type="text"></input>
            </td>
            <td>
                <input id="txt" type="text"></input>
            </td>
            <td>
                <input type="submit"></input>
            </td>
        </tr>
    </form>
</table>

Upvotes: 5

Views: 2276

Answers (5)

Grumpy
Grumpy

Reputation: 2243

It's not proper HTML, but it's sometimes done to lose the empty lines.

Upvotes: -3

Roland Bouman
Roland Bouman

Reputation: 31961

No. see: http://www.w3.org/TR/html4/struct/tables.html#edef-TABLE

<!ELEMENT TABLE - -
 (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)> 

The <form> element can appear in all places where you can have block content. So <form> can go in <body>,<blockquote>,<noscript> (oddly enough also in <map>). Because block can also go in flow, it may also appear in <div>,<ins>,<del>,<dd>,<li>,<td>,<th>

Upvotes: 2

Jan Hančič
Jan Hančič

Reputation: 53931

No this is not valid, TABLE can only contain TBODY, THEAD, TFOOT, CAPTION, COL, COLGROUP. If you are using XHTML then you can also put tr inside the table.

Upvotes: 3

Tor Valamo
Tor Valamo

Reputation: 33749

It's not valid. I'm guessing you want to remove the default padding of the form element. This is better done through CSS:

form {
    padding:0;
    margin:0;
}

or

<form style="padding:0;margin:0;">

Your approach used to be very common to remove the default form padding (before CSS became popular). Now you should put the form tags outside the table. Preferrably you shouldn't even use a table here, but that's not the question, so I'll let it slide. ;)

Upvotes: 8

Flatlin3
Flatlin3

Reputation: 1659

I recomment using the w3c validator http://validator.w3.org/. And no its not valid :-)

Upvotes: 11

Related Questions