Forms are used to handle user input, and allows the user to submit some information.
Forms are to be enclosed within a
<form> tag, with an attribute "action", which points to the script that should be run when a form is submitted.
We don't yet have the tools to process the forms, but in later tutorials, we'll use a back-end server language to do so. :-)
Firstly, we need to make labels for our input fields, which we can with the
<label> tag. We specify which form it's for with the "for" attribute, which is to match with the "id" in our
<input> tag. Now when users click on the label, the focus is placed on the corresponding input.
HTML offers a variety of input elements that we can use to gather data from the user. We use the
<input> element with a "type" attribute.
Additionally, we use the "name" attribute so that we can retrieve the input data once the form is handled. For a standard text box:
<input type="text" name="textbox">
<input type="password" name="password">
<input type="checkbox" checked>
After adding labels for each input field, your form should look somthing like this:
<form> <label for="firstName">First Name</label> <input type="text" name="firstName" id="firstName"> </form>
For a bigger submission box, such as one where you put an "about me", we use the <textarea> tag. It's basically a large, multi-line textbox. The two attributes are "rows" and "cols", specifying the textbox dimensions.
To make select boxes, use the <select> tag.
<select> <option>Banana</option> <option>Kiwi</option> <option>Applie</option> <option>Strawberry</option> </select>
Select your favorite fruit from the following:
To group related objects within a drop-down menu, use <optgroup>
<select> <optgroup label="Swedish Cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> </optgroup> <optgroup label="German Cars"> <option value="mercedes">Mercedes</option> <option value="bmw">BMW</option> </optgroup> </select>
Select a car:
And the most important input button, the submit!
After this button is clicked, the page is redirected to wherever the "action" attribute points to.
This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.$ Check price
Want your web site to display more quickly? This book presents 14 specific rules that will cut 25% to 50% off response time when users request a page. Author Steve Souders, in his job as Chief Performance Yahoo!, collected these best practices while optimizing some of the most-visited pages on the Web.$ Check price