Is it right to use DIV inside FORM?

I'm just wondering what you think of the DIV tag inside the FORM tag?

I need something like this:

<form> <input type="text"/> <div> some </div> <div> another </div> <input type="text" /> </form> 

Is it common practice to use DIV inside FORM or do I need something else?

+63
html semantic-markup
Mar 30 '12 at 12:01
source share
9 answers

This is completely normal.

form will only send controls of its type (* also Textarea , Select , etc.).

You have nothing to worry about the div in the form .

+93
Mar 30 2018-12-12T00:
source share

It is fully legal to use the DIV inside the <form> .

If you look at the CSS 2.1 style sheet , div and p are in the display: block category. Then, looking at the HTML 4.01 specification for the form element, they include not only the <p> tags, but the <table> tags, so of course the <div> will meet the same criteria. There is also a <legend> inside the form in the documentation.

For example, the following passes HTML4 validation in strict mode:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Test</title> </head> <body> <form id="test" action="test.php"> <div> Test: <input name="blah" value="test" type="text"> </div> </form> </body> </html> 
+22
Jan 31 '13 at 19:50
source share

You can use the <div> inside the form - there is no problem .... BUT , if you are going to use the <div> as a label for the input dont ... label is a much better option:

 <label for="myInput">My Label</label> <input type="textbox" name="MyInput" value="" /> 
+6
Mar 30 2018-12-12T00:
source share

Definition and use

A tag defines a division or section in an HTML document.

The tag is used to group element blocks for formatting styles. http://www.w3schools.com/tags/tag_div.asp

Also DIV - MDN

An HTML element (or a document element of an HTML document) is a common container for a stream that is not inherent to represent anything. It can be used to group elements to style goals (using class or identifier attributes) or because they share attribute values, such as lang. It should be used only when no other semantic element (eg, or) is appropriate.

You can use a div inside the form if you are talking about using a div instead of a table, and then google about web design without ads

+2
Mar 30 '12 at 12:05
source share

It is wrong to have <input> as the direct child of the <form>

And by the way, <input / > may fail on some doctype

Check it out with http://validator.w3.org/check




the document type does not allow the use of the "INPUT" element here; one of the starting tags "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" is missing

<input type = "text" />

The specified element is not allowed to appear in the context in which you placed it; the other elements mentioned are the only ones that are allowed there and may contain the element. This may mean that you need a containing element or you may have forgotten to close the previous element.

One possible reason for this message is that you tried to place a block level element (for example, "<p>" or "<table>") inside an inline element (for example, "<a>", "<span>" or "<font>").

+2
Mar 30 2018-12-12T00:
source share

Your question does not address what you want to put in DIV tags, and you probably received some incomplete / incorrect answers. The truth is that you can, as Royey said, put div tags inside your forms. For example, you do not want to do this for shortcuts, but if you have a form with a bunch of flags that you want to lay out in three columns, then by all means, use DIV tags (or SPAN, HEADER, etc. ) ..) to complete the look you are trying to achieve.

+2
Jan 04 '13 at 21:15
source share

As others have said, everything is fine, you can do it just fine. For me personally, I am trying to preserve the form of the hierarchical structure with my elements with a div being the outer main parent element. I am trying to use only inside table p ul and span inside forms. It’s just easier for me to track the relationship between parents and children inside my web pages.

0
Mar 30 '12 at 12:08
source share

Absolutely not! It will be displayed, but it will not be checked. Use the shortcut.

This is not true. It is unavailable. You see this on some websites because some developers are just lazy. When I hire developers, this is one of the first things that I test for candidates. Forms are unpleasant, but take the time and learn how to do them correctly.

-5
Sep 22 '13 at 7:27
source share

No its not

Tags

<div> always used to create a web layout. Its symbolic purpose is to separate the section / part on the page so that a separate style can be added or applied to it. [w3schools Doc] [W3C]

It depends a lot on what you have some and another .

HTML5 has more boolean values ​​than regular tags. section , header , nav , aside all have their own semantic meaning. And used against <div>

-8
Mar 30 '12 at 12:05
source share



All Articles