why someone might use invalid html?

I found some typo(i think so) in code I'm supporting and posted it to local site like a funny example of invalid code. And then some person said me that sometimes this invalid usage is correct.

Can you please explain me why someone might need this code?

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

And also in which cases it can be better then the following?

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

Or this:

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

-----------------EDIT I played a little on jsfiddle and can't find html decision, so maybe that's a reason.

http://jsfiddle.net/WcvFj/3/

But i still think that JS or CSS way would be better

-------------Problems Reply------------

And then some person said me that sometimes this invalid usage is correct.

By definition, invalid code isn't correct.

Can you please explain me why someone might need this code?

With a single cell per row? There isn't even a half good reason. There shouldn't be a table there in the first place because it wouldn't be tabular data.

If there were multiple cells per row, then it would be nice to be able to have a form per row (for an "edit this entry" thing). It isn't necessary though, as you can give each input a unique name, and then determine which row to process based on which submit button was clicked (since only the clicked submit button will be successful and therefore have its name/value pair submitted to the server).

This is a way to get the two form element to align with each other - table based UI alignment. It used to be quite common before CSS was widely supported in browsers.

Today one would do that in CSS with your preferred markup.

As far as I know, example 1 simply is not valid html. Try running it through the validator. However, most browsers will be forgiving enough to not care.

Example 2 and 3 are absolutely fine. Personally I use example 3 in most cases, wrapping all content that "belongs" to the form within the form tag.

Category:html Views:0 Time:2011-04-18

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.079 (s). 11 q(s)