In our previous article, we discussed how to create tables in HTML and how to add data to them. In this episode we will go over forms and how to collect data from users. We will learn to create text fields, radio buttons, check-boxes, buttons, drop-down menus, and much much more. There is a lot of ground to cover in this one, so let's go ahead and get started.
Again you will note that each checkbox has the same name ("nerd"). If they do not, your program will not see them as part of the same set and the results of your form will be skewed.
Drop-Down Boxes
Drop-down boxes allow a user to select from a list of values. Here it is in code:
The above code creates a drop down list of items. You set the values in the list with the <option value> tag. You will also note the selected attribute, which sets the default item in the list. The following is the result of the above code:
Textarea
Users can enter multiple lines of text in a textarea field. In fact, they can enter an unlimited amount of text in the textarea. Here is how you code it:
<html>
<body>
<textarea rows="10" cols="30">
This is some text I am writing as an example. Normally the user writes in here. Once a certain amount of space is taken up, scroll bars will appear on the side of the textarea, allowing the user to scroll up and down.