Forms are used to send information to the web server. Users fill out an interactive form by typing in text boxes, selecting from a list of options, and so on. When you submit a form, all that your browser does is send a long line of text to the host. The server can use it for whatever reason including send e-mail, run an executable, or generate some results for the client. Forms simply display an organized layout to be filled out and sent.
Two common attributes are:http://www.mysite.com/cgi-bin/cool_program.cgi
. Here, the information is processed by cool_program.cgi
. You can also use mailto:JonDoe@hisServer.com
. This would bring up an e-mail client if your users have one setup. mailto
is therefore very unpredictable. Also, it sends out text that's almost unreadable. If you need to send e-mail, use a server-side program.GET
or POST
. GET
is no longer used. It still can be used. POST
is really the only choice.<form action="http://www.mysite.com/cgi-bin/shop.cgi" method="post">
...your code...
</form>
INPUT
element.This is used to display a text-box, password-text-box, checkbox, radio (options), submit [button], reset [button], image [button], custom button, hidden field, and file upload.
A button can be created using the following code:radio
. You can only choose one of many. In group a, the first one is selected. In group b, none are selected. A group of options must have the same name. a different name would mean the radio
is part of a different group.
hidden
type. This one cannot be seen. The code is as follows:
<form>
<input type="hidden" name="cannotBeSeen" value="ImInvisible" >
</form>
text
type. This is a one line text box. Pushing the enter key on your keyboard is the same as clicking on the submit button on your form. The size attribute sets the number of characters the text box can display across. The value attribute sets the default text display when the page is first loaded. The maxlength value sets how many characters can be entered. Once that maximum is reached, no more can be entered. You can set your text to be readonly, this way, the information cannot be altered.
password
type. This resembles a password field you probably see everywhere. It displays an astrisk * for every character you type in.
Select
and Option
element.
This creates a drop-down box or list box with predefined options. Option 2 is selected by default. To choose which one is defualt, insert "selected". Option 4 has the value attribute to it. This is useful if you want to submit cryptic code to the server while showing plain words to your user.
Box 2 shows the same selection, but as a list box showing three items at a time. This is accomplished by adding the size attribute such as size="3"
Box 3 shows a list box that allows multiple selections. To do this put the attribute multiple in the select tag like this
<select name="testlist" size="3" multiple>
Textarea
ElementThe textarea element is similar to the text type in the input element. They are both text boxes that accept user input, you can type in them. This one allows multiple lines. You can have predefined text if you choose. You can set the size of textarea by using the cols and rows attribute. You can also choose the readonly attribute. If you do not want long lines to wrap around you can add the wrap attribute with the value off.
label
element
The label element is new to HTML 4. This is an element like other elements. It contains readonly text that labels another control.
You can associate labels with controls implicitly or explicitly. Implicitly, the element is contained in the label element.
<label>hello <input type="checkbox" name="clickme">implicit</label>
Explicitly, the label is tied in by using the control element's id attribute. The for attribute of the label element is assigned the value of the control element's id attribute. The good thing about explicit association is that label and control elements are separate, so their placement can be structured separately in a table.
fieldset
and legend
elementsThe fieldset puts a box around a group of other objects. The legend places a title at the top. It has the align attribute. This can be left, center, right, and justify. Fieldset and legend does not seem to work on netscape 4, but it will work on Internet Explorer 5 and Netscape 6. This is a relativly new item.