asp.net.ph

Skip Navigation LinksHome > Abakada: Back to Basics > Language References > HTML Elements > FORM Element

<FORM Element | FORM Object


Creates an HTML form.HTML 2, 3.2, 4, 4.01, 5

HTML Syntax

Remarks

The FORM element acts as a container for user input controls. It specifies:

  • The layout of the form, given by the contents of the element.
  • The method by which user data will be sent to the server.
  • The program that will handle the submitted form.
  • A character encoding that must be accepted by the server in order to handle this form. Browsers may advise the user of the accepted character set and/or restrict the user's ability to enter unrecognized characters.

Forms enable client-side users to submit data to a server in a standardized format. Forms can collect data in different ways, using a variety of control elements. Users typically fill in the required data by typing directly into INPUT boxes, by checking options in a radio button or checkbox group, or by selecting options from a dropdown listbox. A submit button is ususally provided to collect and send the form's data to the server.

To be submitted with the form's data set, each of the form controls must be assigned a name and have a valid value. Only controls with a valid name/value pair are sent to the receiving program for processing.

In addition to form controls, a form can contain other elements such as tables, paragraphs, or lists.

Form Control Behavior

When the focus is on a control in a form, pressing ESC once causes the value of the control to revert back to the last value, and pressing the key again resets the form. If the focus is on the form but not on a particular control, pressing ESC once resets the form.

If the form has only one text box, pressing ENTER automatically fires the onsubmit event. If the form has a submit button, the button has a dark border, indicating that pressing ENTER submits the form.

NOTE: Both start and end tags are required.

Attributes

The <form> element supports the following attributes, in addition to global attributes common to all HTML elements.

AttributeValueDescription
accept-charsetcharacter_setSpecifies the character encodings that are to be used for the form submission
actionURLSpecifies where to send the form-data when a form is submitted
autocompleteon, offSpecifies whether a form should have autocomplete on or off
enctypeapplication/x-www-form-urlencoded, multipart/form-data, text/plainSpecifies how the form-data should be encoded when submitting it to the server (only for method="post")
methoddialog, get, postSpecifies the HTTP method to use when sending form-data
nametextSpecifies the name of a form
novalidatenovalidateSpecifies that the form should not be validated when submitted
relexternal, help, license, next, nofollow, noopener, noreferrer, opener, prev, searchSpecifies the relationship between a linked resource and the current document
target_blank, _self, _parent, _topSpecifies where to display the response that is received after submitting the form

Example

The following sample presents a basic form containing a text entry box for searching a keyword. When the submit button is pressed, the form will send the form data to the URL listed in the action property. The value of the method property determines how the data is sent to the server.

Enter keyword:
<form action="..." method="get">
   Enter keyword: <input name="search">
      <input type=submit value="Search"
         onclick="alert ( 'This is just an example, 
            nothing will happen' );return false">
</form>
Notes on DOM Access

A form may be accessed in the following, essentially equivalent, ways:

document.formName
document['formName']
document.forms[formIndex]

An element in a form may be referenced by either its name or id properties.

document.formName.elementName
document['formName'].elementName
document.forms[formIndex].elementName

Or it may also be referenced through the elements collection.

document.formName.elements[controlIndex]
document['formName'].elements[controlIndex]
document.forms[formIndex].elements[controlIndex]
See Also

forms, Form Submission



Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note