Reputation: 10310
I have to create a page with a table, where each row of data is modifiable and can be saved directly by editing the table (think of something like what phpMyAdmin does to allow you to edit a table inline). I have several options before me and I am wondering which is the more semantically correct:
<form>
wrapping my <table>
where each row containing several <input>
s is a child of the same giant <form>
<table>
where each row is a separate <form>
I would be linking every <input>
to a Javascript callback so that the updates are sent to the server automatically every time you change a row. Which route is most in line with the HTML 5 specs?
Upvotes: 0
Views: 33
Reputation: 943585
Create a giant
<form>
wrapping my<table>
where each row containing several<input>
s is a child of the same giant<form>
That is allowed
Create a
<table>
where each row is a separate<form>
That is not allowed
I would be linking every
<input>
to a Javascript callback so that the updates are sent to the server automatically every time you change a row.
That doesn't, technically, require a form at all. You should still have one though so that you can use progressive enhancement and not depend on the JS functioning. Give each form control a row id as part of the name so you can tell which row the data belongs to when the form is submitted.
Upvotes: 1
Reputation: 10447
You can't wrap each row in a form, it's not valid syntax. You can either have a form in each cell (which is a pain) or wrap the whole thing in a form, which is the preferred way for most people.
Another alternative is to do what PHPMyAdmin does, have no forms at all and use Ajax.
Upvotes: 0