Forms are used widely on nearly all Web pages. Web sites collect feedback information, registration details through these forms. If you have ever signed up for free web pages, free email services from yahoo, hotmail etc you may be already aware and familiar with forms. They are applied using <FORM> </FORM> tag. This tag accepts one important attribute namely action, which is used to specify the path for the specified action. HTML forms mainly consist of various form elements, which are specified using <INPUT>tag. This tag accepts many attributes, which are elaborated below along with Form elements.
Text Field
This element is used to enter texts like usernames, addresses etc. Its main attributes are type (value = text), size (value = “Any numeric value”), Maxlength (Value = “Any numeric value”). In the code given below, a user can enter 30 characters initially and then the text scrolls to the left.
Listing 18
<INPUT type = “text” size = “30”>
Buttons
One of the most important form elements is Button. They serve an integral part in an HTML form. They are mainly used to trigger actions. There are two types of buttons, which are Submit and Reset. Submit buttons delivers the entire data on the form to the server while Reset button clears all your previous entries. The important attributes are type (value = Submit or Reset), Value (value = “Any Text like OK, Cancel”). To create a button labeled Click here, you have to code like as shown below:
Listing 19
<INPUT type = “submit” value = “Click here”>
Combo box
These boxes enable you to pick an item from a set of values. They are applied using <SELECT> tag as shown below:
Listing 20
<SELECT name = "s1">
<OPTION>India
<OPTION>USA
<OPTION>UK
</SELECT>
The above code creates a list of 3 countries. However, as said before users can select any one item at a time. You can change this behavior by applying an attribute named multiple as shown below:
Listing 21
<SELECT name = "s1" multiple>
<OPTION>India
<OPTION>USA
<OPTION>UK
</SELECT>