Is it correct to use DIV inside FORM?
I'm just wondering what are you thinking about DIV-tag inside FORM-tag?
I need something like this:
<form>
<input type="text"/>
<div> some </div>
<div> another </div>
<input type="text" />
</form>
Is it general practice to use DIV
inside FORM
or I need something different?
Solution 1:
It is totally fine .
The form
will submit only its input type controls ( *also Textarea
, Select
, etc...).
You have nothing to worry about a div
within a form
.
Solution 2:
It is completely acceptable to use a DIV inside a <form>
tag.
If you look at the default CSS 2.1 stylesheet, div
and p
are both in the display: block
category. Then looking at the HTML 4.01 specification for the form element, they include not only <p>
tags, but <table>
tags, so of course <div>
would meet the same criteria. There is also a <legend>
tag inside the form in the documentation.
For instance, 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>
Solution 3:
You can use a <div>
within a form - there is no problem there .... BUT if you are going to use the <div>
as the label for the input
dont ... label
is a far better option :
<label for="myInput">My Label</label>
<input type="textbox" name="MyInput" value="" />