You are here:   HomeHTML LanguageHTML TutorialHTML MARQUEE
by Dinesh Thakur Category: HTML

An HTML form is a section of a web document into which the user can enter information. This information is passed back to a web server where it might be recorded in a database for future use or perhaps used to control what information is returned to the user.

 

HTML forms can prompt the user to type in some text or choose from a number of options, collect several different items of information at once and can restrict user responses to a se of known values. Including forms in web pages is the most challenging feature for web designers. Forms are used for two-way communication between web pages and web sites.

 

Common uses of forms include

 

Comment response - It is generally used as a way to collect comments from web site viewers and have people suggest improvements.

 

On Line Order Forms - These are now common on the web, provide a way for viewers to order goods from online stores. Order entry forms typically require the user to provide an address, credit card number and other information necessary to facilitate online commerce.

 

Subscription forms - A subscribe Model is adopted by many sites, particularly those that attempt to generate revenue through direct subscriptions or by selling advertising space.

 

Registration forms - These are used to collect information about a user and often are tied to an authentication system, which limits access to the site.

 

Customization forms - Some sites allow the user to select the look and feel for the site itself, literally creating a custom site for each visitor. This form might allow users to specify what topics they are interested in within an online magazine. An HTML form consists of two parts. The first part, the user can see and which he fills out and next one is the part, the users cannot see.

 

The second part specifies how the server should process the user's information you should not that HTML forms cannot provide a fully interactive user interface, they can only construct a query or submission to be fetched like any other web page. There is no way of controlling what is typed into forms fields. Forms only prompt the user for information.

 

To handle the information entered by the user through the form usually requires the provider to write a CGI-based program designed specifically to process submissions from that form.

 

FORM CONTROLS OR WIDGETS

 

A form is made up of fields or controls as well as the markup necessary to structure the form and control it presentation. The controls are the items filled in or manipulated by the user to indicate the state of the form. Form controls include:

 

Text Fields - These are areas for brief text input.

Check boxes - That allow visitors to select none, one or several items from a list use them to elicit multiple answers.

Submit and Reset buttons - These send the form information to the server for processing and return the form to its original settings.

Radio buttons -They give visitors an opportunity to choose only one item:

Text Areas - These are areas for lengthy text input, as in open-ended comments or free form responses.

Select lists - These are lists from which visitors can choose one or more items, use them to present long but finite list of choices.

THE FORM TAG: <FORM>……………………. </FORM>:

In the HTML source code, a form must start with a <FORM> tag and end with a </FORM>tag. It has mainly two attributes "action" and "method".

 

Syntax

 

<FORM action = "URL" method = get | post> form elements </FORM>

 

When you have written a form handler (mainly a CGI program) to which the data in the form will be sent, you will be able to add on action= "URL" attributes to specify the location of the handler.

 

The "method" attribute tells that browser how to send the user's data to the server. It takes either "get" or "post" as its value. Note that the attributes can appear in any order. So you can put method first and then "action" or vice versa.

 

THE INPUT TAG

 

This tag defines an input area within a form. It asks the user to input information in one of several ways. The different ways of input are specified by "type attribute. This attribute can accept text, radio, checkbox, passwords submit, reset, image, hidden, etc. as its value. Each of them will be discussed separately in the coming sections.

 

TEXT FIELDS

 

The most common "type" of form <INPUT> is text. It presents the user with a prompt for a single line of text. These fields are commonly used for a name address, email address, country, postal code etc. It is a blank area within a form and is the place for visitor-supplied information.

 

Syntax

 

<INPUT type = “text" name= “text-id" value= “default-text" size= “n" maxlength = “m" read only>

 

Name: To label the content. This name is not visible to the user and must be unique within the form.

 

Value: To supply initial text to the text field and is optional. The content of this attribute will be shown on the text field, unless the user changes it.

 

Size: To specify the physical size of the text input box. The default value is usually a length of 20 characters.

 

Maxlength: To set the number of characters a user can input. This value should not be less than the value of the size attribute otherwise user won't be able to type to the end of the box and might get confused. The default value of max length is unlimited.

 

Readonly: To lock the predefined content within the text field and the content won't be editable further.

The following code shows the use of above-mentioned attributes:

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25"

MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

</FORM>

</BODY>

</HTML>

 

In the above example, two text fields are included. Each of these fields has a unique name. First field has an initial value, which appears inside the input box. The two text fields are assigned descriptive labels that appeal' on the right of them. If you want the label to come to the left then it should be given before the input tag.

 

Passwords

 

Password fields are similar to text fields, except the contents of the field are not visible on the screen. It displays * * * * (asterisks) instead or the actual input.

 

These fields are mainly used for confidential contents, To establish a password field just set type = "password" in the <INPUT> tag

 

Syntax

 

<INPUT type = "password" name = "password-id" Value = "default-text" size = "n" Maxlength = "m" readonly >

 

All the attributes have same meaning as in the text field except that type is "password". The code for password field is as shown below:

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25"

MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

</FORM>

</BODY>

</HTML>

 

RADIO BUTTONS

 

Radio buttons are mutually exclusive i.e. they allow the user to choose one of the several options. Selecting one turns the other options off. These buttons are viewed in the browser as small circles with a prompt and the selected one appears with a solid dot in it.

 

Syntax

 

<INPUT type = "radio" name = "radio-id" Value = "choice-id" checked>

 

Name: Applies to the collection of buttons, not just to a particular item. Browsers use the name attribute to decide which buttons belong to the same group and therefore which ones are to set and unset as a group.

 

Value: It is the value assigned by the user. These are predefined and they do not accept other input. Each radio button must be assigned a value.

 

Checked: It causes the radio button to be on when the form is first created. It is the default selection.

The code for Radio buttons is as shown below:

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

</FORM>

</BODY>

</HTML>

 

In the above example two radio buttons are added in our form and one is checked by default. Notice that related radio buttons share the same "name" but different values. The data sent by the group of radio buttons when the form is submitted is the value attribute of the selected radio buttons. These values are not seen by the user and are used at the time of form processing.

 

Checkboxes

 

An INPUT tag with attribute type ="checkbox" offers the user an "on" or "off" switch. Each check box works independently from the others, visitors can select or deselect any combination of checkboxes use of these boxes is appropriate for open questions or questions that have more than one "right" answer. Checkboxes appear as square boxes and contain a checkmark when act as a checkbox is switch on when the form is submitted its value attribute is submitted as the form data for the named form component.

 

Syntax

<INPUT type = "Checkbox" name ="box -id" Value = "choice-id" checked>

 

Name: To specify separate name for each checkbox. Unlike radio buttons, each item has a separate label. Although the checkboxes visually appear as a set, logically the items are completely separate.

 

Value: To provide a descriptive value for each checkbox.

Checked: To specify default selection.

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<INPUT TYPE=”CHECKBOX” NAME=”VEHICAL” VALUE=” VEHICAL” CHECKED>OWN VEHICAL<BR>

<INPUT TYPE=”CHECKBOX” NAME=”HOSTEL” VALUE=” HOSTEL” >HOSTEL REQUIRED<BR>

</FORM>

</BODY>

</HTML>

 

Pull Down Lists

 

A pull down menu lets the user select one choice out of many possible choices. One nice aspect of pull-down menus is that all choices do not have to be seen on the screen and are normally hidden. They occupy minimal amount of space as it displays only on item of the list. In this kind of input field you use <SELECT>instead of <INPUT> and it has a closing tag.

 

Syntax

<SELECT name = "text-id" size="n" multiple >

<OPTION Value = "Choice-id" selected> Text Label -1 </OPTION>

…………………………………………………………..

…………………………………………………………..

 

<OPTION Value = "Choice id m" selected> TEXT LABEL. - m </OPTION>

</SELECT>

 

Name: To establish a name for the select field and is used for form processing.

Size: The number of options you want to show in the window. By default its value is one, specifying size value greater than one turns the pull down list into a scrolling list. In the SELECT field, by default, the user can select only one field.

Multiple: To set the SELECT field to accept any number of options. To select multiple options press ctrl key and click on the options.

<OPTION> Tag: To include the list items. For each list item there must be an <option> tag "The closing" tag is optional.

Value: Whenever a form is submitted, the options in the pull down list are passed to the form handles using the "Value" attribute. If the "Value" attribute is omitted the contents of the option are used instead.

Selected: This attribute is used to specify the default other than the first option. More than the first option- More than one option can be made default by using this attribute but in that case you just include the multiple attribute, otherwise the last option having selected attribute will be considered as default. The defaults will appear when the form is loaded or reset. The following lines of code will add a pull down list to our sample form.

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<SELECT NAME =”COUNTRY”>

<OPTION VALUE = “INDIA”>INDIA

<OPTION VALUE = “AMERICA”> AMERICA

<OPTION VALUE = “AUSTRALIA”> AUSTRALIA

<OPTION VALUE = “NEW ZEALAND”> NEW ZEALAND

<OPTION VALUE = “CHINA”> CHINA

</SELECT><B>COUNTRY</B>

</FORM>

</BODY>

</HTML>

 

But if the "multiple" attribute is included, the list will become a scrolling list. This attribute is added in the <SELECT> tag as shown below:

 

<SELECT NAME="COUNTRY" MULTIPLE>

<OPTION VALUE="INDIA">INDIA

<OPTION VALUE=" AMERICA" SELECTED>AMERICA

<OPTION VALUE="AUSTRALIA">AUSTRALIA

<OPTION VALUE="NEW ZEALAND">NEW ZEALAND

<OPTION VALUE="CHINA">CHINA

</SELECT><B>COUNTRY</B>

 

The TEXTAREA tag

 

This tag is used to set an area within a form in which the user can type a large amount of text. The textarea's are basically used for giving comments and free form feedback from visitors.

 

Syntax

 

<TEXTAREA name = "text-id" rows = "n" Cols = "m" Wrap= "Virtual physically off" read only> Initial content </TEXT AREA>

 

TEXTAREA: Sets an area in a form for lengthy visitor input. Initial content for the text area goes between the opening & closing tags. Rows: This attribute specifies the height of the text area. Cols: This attribute specifies the width of the text area.

Wrap: If you turn wrap off the text is handled as one long sequence of text without line breaks. If you set it to virtual the text appears on your page as if it recognized line breaks but when the form is submitted the line breaks are turned off. If you set it to physical the text is submitted exactly as it appears on the screen line breaks included.

Readonly: It prevents the user to alter the initial content.

 

The following lines of code will add a TEXTAREA in our sample form.

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<SELECT NAME =”COUNTRY”>

<OPTION VALUE = “INDIA”>INDIA

<OPTION VALUE = “AMERICA”> AMERICA

<OPTION VALUE = “AUSTRALIA”> AUSTRALIA

<OPTION VALUE = “NEW ZEALAND”> NEW ZEALAND

<OPTION VALUE = “CHINA”> CHINA

</SELECT><B>COUNTRY</B>

<TEXTAREA NAME="COMMENTS" ROWS=2 COLS=20 WRAP="VIRTUAL:”> PLACE YOUR COMMENTS HERE: </TEXTAREA> <B> COMMENTS </B>

</FORM>

</BODY>

</HTML>

 

RESET AND SUBMIT BUTTONS

 

SUBMIT- After filling up the form, the user needs to submit the information. An <INPUT> tag with type = submit provides a button that submits the information in the completed form to the URL, given as the action attribute of the FORM tag.

 

The information is submitted using the HTTP request type specified by Form's method attribute discussed in details in topic entitled ("Processing Forms")

 

Syntax

 

<INPUT type = "submit" Value = "button label text" >

 

Value: This attribute will change the text mentioned on the button just substitute your text in the value attribute. By default "submit" as written over the button. The button size will be controlled directly by the text length.

RESET: The reset value of the type attribute clears all form entries to the default one or leaves them blank if no defaults are specified Not al HTML forms will use this feature, but it can help users to start afresh or if they want to reconsider the default options.

Syntax

 

<INPUT type = "reset" Value =" button label text">

 

The "Value" attribute again is used to specify the text on the button. These buttons can be placed anywhere in the form. But the best place for them is below all the other input fields.

The following lines of code will add these buttons to our sample form.

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<SELECT NAME =”COUNTRY”>

<OPTION VALUE = “INDIA”>INDIA

<OPTION VALUE = “AMERICA”> AMERICA

<OPTION VALUE = “AUSTRALIA”> AUSTRALIA

<OPTION VALUE = “NEW ZEALAND”> NEW ZEALAND

<OPTION VALUE = “CHINA”> CHINA

</SELECT><B>COUNTRY</B>

<TEXTAREA NAME="COMMENTS" ROWS=2 COLS=20 WRAP="VIRTUAL:”> PLACE YOUR COMMENTS HERE: </TEXTAREA> <B> COMMENTS </B>

<P ALIGN=CENTER>

<INPUT TYPE=”SUBMIT” VALUE=”SUBMIT”>

<INPUT TYPE=”RESET” VALUE=”RESET”>

</FORM>

</BODY>

</HTML>

 

An image can also be used for submit button. The image value of the "type" attribute provides a graphical submit button. It works exactly same as the submit button.

 

Syntax

 

<INPUT type = "image" src = "image_url" height = "n" width = "m"

alt = "alternative text " "border = 0" >

 

src: This attribute gives the URL of the image source file.

Width: To specify the width of image.

Height: To specify the height of image.

 

Alt: On rolling mouse over the image, the text mentioned is displayed. If someone is running without images they can still submit the form.

Border: To specify border for the image. In the syntax it turns off the border. The image value is by default for a submit button only. It cannot make a reset image button.

The following code adds an image submit button to our sample form.

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<SELECT NAME =”COUNTRY”>

<OPTION VALUE = “INDIA”>INDIA

<OPTION VALUE = “AMERICA”> AMERICA

<OPTION VALUE = “AUSTRALIA”> AUSTRALIA

<OPTION VALUE = “NEW ZEALAND”> NEW ZEALAND

<OPTION VALUE = “CHINA”> CHINA

</SELECT><B>COUNTRY</B>

<TEXTAREA NAME="COMMENTS" ROWS=2 COLS=20 WRAP="VIRTUAL:”> PLACE YOUR COMMENTS HERE: </TEXTAREA> <B> COMMENTS </B>

<P ALIGN=CENTER>

<INPUT TYPE=”IMAGE” SRC=”C:\WINDOWS\HLPGLOBE.GIF” ALT=”SUBMIT” WIDTH = 55 HEIGHT = 40>

<INPUT TYPE=”RESET” VALUE=”RESET”>

</FORM>

</BODY>

</HTML>

 

SPECIAL < INPUT> TYPES

 

FILES

 

HTML also supports a special input field, a file field, to allow visitors to upload files. If you want visitors to submit information - say a picture, a spreadsheet, a word-processed document or a scanned document, they can use this field to simply upload the file with the hassle of using FTP or e-mail the file.

 

Syntax

 

<INPUT type = “file" name = "field-id" size = “n" accept = “file-type" >

 

Name: To label the field

Size: To specify the physical size of the field's input box.

Accept: To restrict the file types allowed in a file upload. For example add accept = "image/ gif" to occupy only gif files

To include files of some specific types, just separate them by commas. For example to include BOTH .gif and .jpeg files, the following code can be used.

Accept = “image/gif, image/jpeg "

When the form is loaded or reset, a button labeled "Browse" together with a text box for writing the file name appears on the window. As the user clicks on this button a new window “choose file” will open and the user can select the desired file. The following code will add a file field.

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<SELECT NAME =”COUNTRY”>

<OPTION VALUE = “INDIA”>INDIA

<OPTION VALUE = “AMERICA”> AMERICA

<OPTION VALUE = “AUSTRALIA”> AUSTRALIA

<OPTION VALUE = “NEW ZEALAND”> NEW ZEALAND

<OPTION VALUE = “CHINA”> CHINA

</SELECT><B>COUNTRY</B>

<TEXTAREA NAME="COMMENTS" ROWS=2 COLS=20 WRAP="VIRTUAL:”> PLACE YOUR COMMENTS HERE: </TEXTAREA> <B> COMMENTS </B>

<INPUT TYPE=”FILE” NAME =”ATTACHEMENTS” SIZE=”30” ACCEPT=”IMAGE/JPG”> <B> ATTACHEMENTS</B>

<P ALIGN=CENTER>

<INPUT TYPE=”IMAGE” SRC=”C:\WINDOWS\HLPGLOBE.GIF” ALT=”SUBMIT” WIDTH = 55 HEIGHT = 40>

<INPUT TYPE=”RESET” VALUE=”RESET”>

</FORM>

</BODY>

</HTML>

 

Hidden Value

 

The input "type" = hidden is unusual in the respect that they do not appear in the displayed form. By setting the "type" attribute to hidden, it is possible to transmit default or previously specified text that is hidden from the user to the handling program. It is a convenient tool for the web designer. It can be used to hold contextual information, such as the name of the form (useful when the same form handles is used for several different forms), where to send the passed data etc.

 

A hidden input does not show up anywhere on the web page. The visitors would not be able to see it unless they see your page source. This input is recognized only by the form handler program mainly CGI (scripts) that receives the user's information from the form.

 

Syntax

 

<INPUT type = "hidden" name = "data-id" Value = "hidden form data" >

 

Name: To label the hidden data

Value: It specifies the destination where the hidden form data is to be sent. The value attribute is passed as the form data for the name attribute, but the user cannot see any representation of this form component on the screen and is not prompted to change the form component contents.

One of the best use of the hidden input is to tell the form handler where to send the processed data and where to send your visitor after he fills out your form.

Examples:

<INPUT type = hidden name = "send processed data to" Value ="ecomputernotes.com" >

 

The FIELDSET and LEGEND Tags

 

<FIELDSET>tag creates a box around a group of widgets and <LEGEND>tag provides a label to the field set. Both tags require closing tags.

 

Syntax

 

<FIELDSET> control 1 control 2……………………. Control n < /FIELDSET>

<LEGEND> Group label Text</LEGEND>

 

The following code shows the use of both of these tags:

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<FIELDS>

<LEGEND><H2>DETAIL</H2></LEGEND>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<SELECT NAME =”COUNTRY”>

<OPTION VALUE = “INDIA”>INDIA

<OPTION VALUE = “AMERICA”> AMERICA

<OPTION VALUE = “AUSTRALIA”> AUSTRALIA

<OPTION VALUE = “NEW ZEALAND”> NEW ZEALAND

<OPTION VALUE = “CHINA”> CHINA

</SELECT><B>COUNTRY</B>

<TEXTAREA NAME="COMMENTS" ROWS=2 COLS=20 WRAP="VIRTUAL:”> PLACE YOUR COMMENTS HERE: </TEXTAREA> <B> COMMENTS </B>

<FIELDSET>

<INPUT TYPE=”FILE” NAME =”ATTACHEMENTS” SIZE=”30” ACCEPT=”IMAGE/JPG”> <B> ATTACHEMENTS</B>

<P ALIGN=CENTER>

<INPUT TYPE=”IMAGE” SRC=”C:\WINDOWS\HLPGLOBE.GIF” ALT=”SUBMIT” WIDTH = 55 HEIGHT = 40>

<INPUT TYPE=”RESET” VALUE=”RESET”>

</FORM>

</BODY>

</HTML>

In the above window all the <INPUT> field types have been grouped and labeled as DETAILS

 

Disabled Attribute

 

This attribute disables a form element. The element contents are not only unalterable, but also unusable. It can be applied to any INPUT tag, as well as to the SELECT, OPTION, TEXTAREA tags. So to disable the File field.

 

The code is written as below:

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<FIELDS>

<LEGEND><H2>DETAIL</H2></LEGEND>

<P>

<INPUT TYPE ="TEXT" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25" MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25" MAXLENGTH="30"><BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30">

ADDRESS<BR><BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”MALE” CHECKED>MALE<BR>

<INPUT TYPE=”RADIO” NAME=”SEX” VALUE=”FEMALE” >FEMALE<BR>

<SELECT NAME =”COUNTRY”>

<OPTION VALUE = “INDIA”>INDIA

<OPTION VALUE = “AMERICA”> AMERICA

<OPTION VALUE = “AUSTRALIA”> AUSTRALIA

<OPTION VALUE = “NEW ZEALAND”> NEW ZEALAND

<OPTION VALUE = “CHINA”> CHINA

</SELECT><B>COUNTRY</B>

<TEXTAREA NAME="COMMENTS" ROWS=2 COLS=20 WRAP="VIRTUAL:”> PLACE YOUR COMMENTS HERE: </TEXTAREA> <B> COMMENTS </B>

<FIELDSET>

<INPUT TYPE=”FILE” NAME =”ATTACHEMENTS” SIZE=”30” ACCEPT=”IMAGE/JPG” DISABLED> <B> ATTACHEMENTS</B>

<P ALIGN=CENTER>

<INPUT TYPE=”IMAGE” SRC=”C:\WINDOWS\HLPGLOBE.GIF” ALT=”SUBMIT” WIDTH = 55 HEIGHT = 40>

<INPUT TYPE=”RESET” VALUE=”RESET”>

</FORM>

</BODY>

</HTML>

While submitting the form, the name/value pairs of disabled form elements are not included.

 

NAVIGATING THROUGH A FORM

 

Now we will be discussing how to navigate through a particular form. By default, you navigate through the form in the order in which elements appear in the form, using tab index attribute you can change this default order. Just place the tabindex attribute in the input field. Our sample form shows the following fields and they will be accessed in the order they are listed. Using the tabindex attribute the order will change. The following code shows the new order as below:

 

<HTML>

<HEAD><TITLE> TEXT FIELDS</TITLE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT' tabindex="30" NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25"

MAXLENGTH="30"> NAME<BR><BR>

<INPUT TYPE ="PASSWORD" tabindex="20" NAME="PASSWD" SIZE="25"

MAXLENGTH="30"> PASSWORD<BR><BR>

<INPUT TYPE ="TEXT" tabindex="40" NAME="ADDRESS" SIZE="25"

MAXLENGTH="30"> ADDRESS<BR><BR>

<INPUT TYPE ="RADIO" tabindex="10" NAME="SEX" VALUE="MALE" CHECKED> MALE<BR>

 </FORM>

</BODY>

</HTML>

 

If two elements have the same tabindex value, the orders will be same as the default order i.e. in which they appear. You can also remove an input field from the tab navigation order by assigning it a negative tabindex value. This attribute can be used with INPUT, SELECT and TEXTAREA elements.

 

ACCESS KEYS

 

To access the form elements the user either clicks the mouse or uses the tab key. You can give your visitors a direct keyboard access by using access key attribute. This attribute specifies the character that you assign to the form element as a particular hot key. When the key is pressed together with the "alt" key, the corresponding form element gets activated. When assigning characters for access key, always be careful that they do not override the browser's own access keys. Also function keys (Fl-F12) cannot be made access keys, as they have already been assigned a function.

Otherwise the access key defined by you will get preference over the browser's access key.

The following code will assign access keys to different fields of our sample form and these can be accessed using "Alt" key combination.

<HTML>

<HEAD><TITIE> TEXT FIEIDS</TITIE></HEAD>

<BODY BGCOLOR="PINK">

<P ALIGN ="CENTER"><B>ADMISSION FORM</B>

<FORM>

<P>

<INPUT TYPE ="TEXT” NAME="NAME" VALUE="ENTER YOUR NAME:" SIZE="25"

MAXLENGTH="30" accesskey="N"> <U>N</U>AME<BR><BR>

<INPUT TYPE ="PASSWORD" NAME="PASSWD" SIZE="25"

MAXLENGTH="30" accesskey="P"> <U>P</U>PASSWORD<BR><BR>

<INPUT TYPE ="TEXT" NAME="ADDRESS" SIZE="25" MAXLENGTH="30"

accesskey=" A"> <U>A</U>ADDRESS<BR><BR>

<INPUT TYPE ="RADIO" NAME="SEX" VALUE="MALE" accesskey="M" CHECKED><U>M</U>ALE<BR>

<INPUT TYPE ="RADIO" NAME="SEX" VALUE="FEMALE" accesskey="F"> <U>F</U>FEMALE<BR>

</FORM>

</BODY> </HTML>





About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Search Content







Advance Courses



Basic Courses



Advertise with Us