OIT > WCG > Code Library > Sample Form
Sample Form
The elements <fieldset> and <legend> allow you to layout and organise a large form with many different areas of interest in a logical way without using tables. The <fieldset> tag can be used to create boxes around selected elements and the <legend> tag will give a caption to those elements. In this way form elements can be grouped together into identified categories.
The tags <label for> and <id> can be used to associate a text or graphic label with a specific form input (or control). The tags can be used with any of the input elements, for example text boxes, text area, checkboxes and radio buttons; however, the id attribute for each element (checkbox, text field etc) in a document must be unique.
While it is usual for the form label or prompt and the control to be adjacent to each other, or at least in close proximity, it is possible to associate a label with a form control that is placed anywhere on the same Web page.
A <tabindex> can be included, allowing the user to easily move from one form element to the next per the predetermined <tabindex> order established in the code. Tab order ascends from lowest to highest number.
Sample Form
HTML Code
- <form class="validate" id="sample_form" name="sample_form">
- <fieldset class="login">
- <legend>Login Details</legend>
- <div>
- <label for="username">User Name</label> <input id="username" name="username" type="text" />
- </div>
- <div>
- <label for="password">Password</label> <input id="password" name="password" type="password" />
- </div>
- <div>
- <label for="password2">Retype Password</label> <input id="password2" name="password2" type="password" />
- </div>
- </fieldset>
- <fieldset class="contact">
- <legend>User Details</legend>
- <div>
- <label for="firstname">First Name</label> <input id="firstname" name="firstname" type="text" />
- </div>
- <div>
- <label for="lastname">Last Name</label> <input id="lastname" name="lastname" type="text" />
- </div>
- <div class="radio">
- <fieldset>
- <legend><span>Gender</span></legend>
- <div>
- <input id="male" name="gender" value="male" type="radio" /> <label for="male">Male</label>
- </div>
- <div>
- <input id="female" name="gender" value="female" type="radio" /> <label for="female">Female</label>
- </div>
- </fieldset>
- </div>
- <div>
- <label for="email">Email</label> <input class="email" id="email" name="email" type="text" />
- </div>
- </fieldset>
- <button class="submitBtn" value="submit"><span>Submit</span></button>
- </form>
CSS Code