JavaScript Form Object

The JavaScript Form Object is a property of the document object. This corresponds to an HTML input form constructed with the FORM tag. A form can be submitted by calling the JavaScript submit method or clicking the form submit button.

Form Object Properties

  • action - This specifies the URL and CGI script file name the form is to be submitted to. It allows reading or changing the ACTION attribute of the HTML FORM tag.
  • elements - An array of fields and elements in the form.
  • encoding - This is a read or write string. It specifies the encoding method the form data is encoded in before being submitted to the server. It corresponds to the ENCTYPE attribute of the FORM tag. The default is "application/x-www-form-urlencoded". Other encoding includes text/plain or multipart/form-data.
  • length - The number of fields in the elements array. I.E. the length of the elements array.
  • method - This is a read or write string. It has the value "GET" or "POST".
  • name - The form name. Corresponds to the FORM Name attribute.
  • target - The name of the frame or window the form submission response is sent to by the server. Corresponds to the FORM TARGET attribute.

Form Objects

Forms have their own objects.

  • button - An GUI pushbutton control. Methods are click(), blur(), and focus(). Attributes:
    • name - The name of the button
    • type - The object's type. In this case, "button".
    • value - The string displayed on the button.
  • checkbox - An GUI check box control. Methods are click(), blur(), and focus(). Attributes:
    • checked - Indicates whether the checkbox is checked. This is a read or write value.
    • defaultChecked - Indicates whether the checkbox is checked by default. This is a read only value.
    • name - The name of the checkbox.
    • type - Type is "checkbox".
    • value - A read or write string that specifies the value returned when the checkbox is selected.
  • FileUpload - This is created with the INPUT type="file". This is the same as the text element with the addition of a directory browser. Methods are blur(), and focus(). Attributes:
    • name - The name of the FileUpload object.
    • type - Type is "file".
    • value - The string entered which is returned when the form is submitted.
  • hidden - An object that represents a hidden form field and is used for client/server communications. No methods exist for this object. Attributes:
    • name - The name of the Hidden object.
    • type - Type is "hidden".
    • value - A read or write string that is sent to the server when the form is submitted.
  • password - A text field used to send sensitive data to the server. Methods are blur(), focus(), and select(). Attributes:
    • defaultValue - The default value.
    • name - The name of the password object."
    • type - Type is "password".
    • value - A read or write string that is sent to the server when the form is submitted.
  • radio - A GUI radio button control. Methods are click(), blur(), and focus(). Attributes:
    • checked - Indicates whether the radio button is checked. This is a read or write value.
    • defaultChecked - Indicates whether the radio button is checked by default. This is a read only value.
    • length - The number of radio buttons in a group.
    • name - The name of the radio button.
    • type - Type is "radio".
    • value - A read or write string that specifies the value returned when the radio button is selected.
  • reset - A button object used to reset a form back to default values. Methods are click(), blur(), and focus(). Attributes:
    • name - The name of the reset object.
    • type - Type is "reset".
    • value - The text that appears on the button. By default it is "reset".
  • select - A GUI selection list. This is basically a drop down list. Methods are blur(), and focus(). Attributes:
    • length - The number of elements contained in the options array.
    • name - The name of the selection list.
    • options - An array each of which identifies an options that may be selected in the list.
    • selectedIndex - Specifies the current selected option within the select list
    • type - Type is "select".
  • submit - A submit button object. Methods are click(), blur(), and focus(). Attributes:
    • name - The name of the submit button.
    • type - Type is "submit".
    • value - The text that will appear on the button.
  • text - A GUI text field object. Methods are blur(), focus(), and select(). Attributes:
    • defaultValue - The text default value of the text field.
    • name - The name of the text field.
    • type - Type is "text".
    • value - The text that is entered and appears in the text field. It is sent to the server when the form is submitted.
  • textarea - A GUI text area field object. Methods are blur(), focus(), and select(). Attributes:
    • defaultValue - The text default value of the text area field.
    • name - The name of the text area.
    • type - Type is textarea.
    • value- The text that is entered and appears in the text area field. It is sent to the server when the form is submitted.



Form Object Methods

  • reset() - Used to reset the form elements to their default values.
  • submit() - Submits the form as though the submit button were pressed by the user.

Events

  • onReset
  • onSubmit