Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

forms

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.

like image 371
mickwaffle Avatar asked May 08 '11 21:05

mickwaffle


People also ask

Can we use form inside a table?

Tables and forms can be nested either way. But if you put forms into tables, each form must be completely included into a single table cell (one TD element in practice).

How do you create a form table in HTML?

To make a table in HTML, use the <table> tag. Within this table tag, you'll place the <tr>, <th>, and <td> tags. The <tr> tag defines a table row. The <th> tag defines the table header.

How do you put a form in a box in HTML?

Definition and Usage. The <fieldset> tag is used to group related elements in a form. The <fieldset> tag draws a box around the related elements.


2 Answers

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; }
like image 123
c-smile Avatar answered Sep 20 '22 09:09

c-smile


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.

like image 45
musaul Avatar answered Sep 18 '22 09:09

musaul