mickwaffle
mickwaffle

Reputation: 61

Is it possible to insert a form within an html table?

Multiple forms in one table, these forms last for varying lengths of rows, however this does not seem to work:

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

I believe a table has a definite structure, and this cannot be interlaced with other structures, but is there a tidy work around this?

Thanks.

Upvotes: 6

Views: 7228

Answers (6)

JustAnotherNetizen
JustAnotherNetizen

Reputation: 115

It would be a problem in all HTML ... including both XHTML and HTML5.

XHTML table dtd ..

<!ELEMENT table (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>

Upvotes: 1

cvsguimaraes
cvsguimaraes

Reputation: 13240

Yes! No problem to HTML5. Now table tags are just a shorthand for table styling rules.

Upvotes: 0

c-smile
c-smile

Reputation: 27460

No. According to this document: http://www.w3.org/TR/html401/struct/tables.html#h-11.2.1 table may contain only these:

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

But you can use something like this

<div class=table>
  <form>
    <div class=cell>...</div>   
    <div class=cell>...</div>   
  </form>
</div>

with styles:

div.table { display:table; }
div.table > form { display:table-row; }
div.table > form > div.cell { display:table-cell; }

Upvotes: 5

ajcl
ajcl

Reputation: 381

There's no real need to have two forms in a single table if you're looking to put them on multiple rows. The bigger the table, the longer it takes for the browser to load and display it. Instead, give each form its own table and place the table tags within the form tags, like so:

<form method="GET" action="foo.sh">
  <table>
  </table>
</form>

Upvotes: 0

musaul
musaul

Reputation: 2341

No, you can't do that. I guess you want it that way to have both forms aligned in a table, right?

If you are allowed javascript on the page, you could add the different text boxes etc. inside the <td> elements, and attach onchange event handlers to these boxes to populate the corresponding (hidden) fields in your actual forms.

Upvotes: 2

ataddeini
ataddeini

Reputation: 4951

Not between <tr> tags. They should work outside of <table> or inside of <td> though.

Upvotes: 0

Related Questions