Table of Contents

Class HTMLFormElement

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The HTMLFormElement interface represents a form element in the DOM. It allows access to—and, in some cases, modification of—aspects of the form, as well as access to its component elements.

[Value("HTMLFormElement")]
public class HTMLFormElement : HTMLElement
Inheritance
HTMLFormElement
Inherited Members

Remarks

-The HTML element implementing this interface: form.

See also on MDN

Constructors

HTMLFormElement()

public HTMLFormElement()

Properties

AcceptCharset

The HTMLFormElement.acceptCharset property represents the character encoding for the given {{htmlelement("form")}} element.

[Value("acceptCharset")]
public string AcceptCharset { get; set; }

Property Value

string

A string which may be a case-insensitive match for UTF-8.

Remarks

The specification allows a single case-insensitive value of "UTF-8", reflecting the ubiquity of this encoding (historically multiple character encodings could be specified as a comma-separated or space-separated list).

This reflects the value of the form's accept-charset HTML attribute.

See also on MDN

Action

The HTMLFormElement.action property represents the action
of the form element.

[Value("action")]
public string Action { get; set; }

Property Value

string

A string.

Remarks

The action of a form is the program that is executed on the server when the form is
submitted. This property can be retrieved or set.

See also on MDN

Autocomplete

The autocomplete property of the HTMLFormElement interface indicates whether the value of the form's controls can be automatically completed by the browser. It reflects the {{htmlelement("form")}} element's autocomplete attribute.

[Value("autocomplete")]
public string Autocomplete { get; set; }

Property Value

string

A string; the value "off" if explicitly set to "off", and otherwise always "on".

Remarks

Elements

The elements property of the HTMLFormElement interface returns an HTMLFormControlsCollection listing all the listed form controls associated with the {{HTMLElement("form")}} element.

[Value("elements")]
public HTMLFormControlsCollection Elements { get; }

Property Value

HTMLFormControlsCollection

An HTMLFormControlsCollection containing all non-image controls associated with the form.
This is a live collection; if form controls are associated with or disassociated from the form, this collection will update to reflect the change.The form controls in the returned collection are in the same order in which they appear in the document by following a preorder, depth-first traversal of the tree.
This is called tree order.Only the following form controls are returned:

Remarks

You can access a particular form control in the returned collection by using either an index or the element's name or id attributes.

Prior to HTML 5, the returned object was an HTMLCollection, on which HTMLFormControlsCollection is based.

Independently, you can obtain just the number of associated form controls using the Length property. You can get a list of all of the forms contained within a given document using the document's Forms property.

See also on MDN

Encoding

The HTMLFormElement.encoding property is an alternative name for the Enctype element on the DOM HTMLFormElement object.

[Value("encoding")]
public string Encoding { get; set; }

Property Value

string

Remarks

Enctype

The HTMLFormElement.enctype property is the MIME_type of content that is used
to submit the form to the server. Possible values are:

[Value("enctype")]
public string Enctype { get; set; }

Property Value

string

A string.

Remarks

This value can be overridden by a formenctype attribute
on a button or input element.

See also on MDN

Length

The HTMLFormElement.length
read-only property returns the number of controls in the form
element.

[Value("length")]
public ulong Length { get; }

Property Value

ulong

A number.

Remarks

You can access the list of the form's controls using the
Elements property.

This includes both elements that are descendants of the <form>
element as well as elements that are made members of the form using their
form property.

Elements that are considered for this property are: button,
fieldset, input (with the exception
that any whose type is "image" are omitted for historical reasons),
object, output, select,
and textarea.

See also on MDN

Method

The HTMLFormElement.method property represents the
HTTP method used to submit the {{HtmlElement("form")}}.

[Value("method")]
public string Method { get; set; }

Property Value

string

A string.

Remarks

Unless explicitly specified, the default method is 'get'.

See also on MDN

Name

The HTMLFormElement.name property represents the name of
the current form element as a string.

[Value("name")]
public string Name { get; set; }

Property Value

string

A string.

Remarks

If your Form element contains an element named name then
that element overrides the form.name property, so that you can't access it.

See also on MDN

NoValidate

The noValidate property of the HTMLFormElement interface is a boolean value indicating if the {{htmlelement("form")}} will bypass constraint validation when submitted. It reflects the <form> element's novalidate attribute; if the attribute present, the value is true.

[Value("noValidate")]
public bool NoValidate { get; set; }

Property Value

bool

A boolean.

Remarks

If this attribute is not set or the value is set to false, the form is validated. This can be overridden by setting the FormNoValidate or FormNoValidate property to true, either via JavaScript or the HTML formnovalidate attribute, for the control used to submit the form.

This property can be retrieved or set.

-ReportValidity()
-CheckValidity()
-Action
-Enctype
-Method
-Target
-form
-Learn: Client-side form validation
-Guide: Constraint validation

See also on MDN

Rel

The rel property of the HTMLFormElement interface reflects the rel attribute. It is a string containing what kinds of links the HTML form element creates, as a space-separated list of enumerated values.

[Value("rel")]
public string Rel { get; set; }

Property Value

string

A string.

Remarks

To retrieve the value as an array of tokens, use RelList.

-RelList
-Rel
-Rel

See also on MDN

RelList

The relList read-only property of the HTMLFormElement interface reflects the rel attribute. It is a live DOMTokenList containing the set of link types indicating the relationship between the resource represented by the {{HTMLElement("form")}} element and the current document.

[Value("relList")]
public DOMTokenList RelList { get; }

Property Value

DOMTokenList

A live DOMTokenList of strings.

Remarks

The property itself is read-only, meaning you can not reassign the property with another DOMTokenList, but the content of the returned list can be changed.

To retrieve a string containing the values as space-separated tokens, use Rel. The rel property can also be used to set the rel attribute value.

-RelList
-RelList
-Rel

See also on MDN

Target

The target property of the HTMLFormElement
interface represents the target of the form's action (i.e., the frame in which to render
its output).

[Value("target")]
public string Target { get; set; }

Property Value

string

A string.

Remarks

Methods

CheckValidity()

The checkValidity() method of the HTMLFormElement interface returns a boolean value which indicates if all associated controls meet any constraint validation rules applied to them. The method also fires an HTMLElementinvalid event on each invalid element, but not on the form element itself. Because there's no default browser behavior for checkValidity(), canceling this invalid event has no effect.

[Value("checkValidity")]
public bool CheckValidity()

Returns

bool

Returns true if the associated controls' values have no validity problems; otherwise, returns false.

Remarks

NOTE

The :valid and :invalid CSS pseudo-classes are applied to <form> elements based on the validity of its owned form controls, not the validity of the <form> element itself.

-ReportValidity()
-form
-Learn: Client-side form validation
-Guide: Constraint validation

See also on MDN

ReportValidity()

The reportValidity() method of the HTMLFormElement interface performs the same validity checking steps as the CheckValidity() method. In addition, for each HTMLElementinvalid event that was fired and not canceled, the browser displays the problem to the user.

[Value("reportValidity")]
public bool ReportValidity()

Returns

bool

Returns true if the associated controls' values have no validity problems; otherwise, returns false.

Remarks

RequestSubmit(HTMLElement?)

The HTMLFormElement method requestSubmit() requests
that the form be submitted using a specific submit button.

[Value("requestSubmit")]
public GlobalObject.Undefined RequestSubmit(HTMLElement? submitter = null)

Parameters

submitter HTMLElement

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Reset()

The HTMLFormElement.reset() method restores a form
element's default values. This method does the same thing as clicking the form's
<input type="reset"> control.

[Value("reset")]
public GlobalObject.Undefined Reset()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

If a form control (such as a reset button) has a name or id of reset it will
mask the form's reset method. It does not reset other attributes in the input, such as
disabled.

Note that if SetAttribute(string, string) is called to set
the value of a particular attribute, a subsequent call to reset() won't
reset the attribute to its default value, but instead will keep the attribute at
whatever value the SetAttribute(string, string) call set it to.

See also on MDN

Submit()

The HTMLFormElement.submit() method submits a given
form.

[Value("submit")]
public GlobalObject.Undefined Submit()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

This method is similar, but not identical to, activating a form's submit
button. When invoking this method directly, however:

The RequestSubmit(HTMLElement?) method is identical to activating a
form's submit button and does not have these differences.

A form control (such as a submit button) with a name or id of submit will mask the form's submit method. Trying to call myForm.submit(); throws an error "submit is not a function" because in this case submit refers to the form control which has a name or id of submit.

input with attribute type="submit" will not be submitted with the
form when using HTMLFormElement.submit(), but it would be
submitted when you do it with original HTML form submit.

See also on MDN