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.
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.
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.
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
-form
-HTML autocomplete attribute
-ARIA aria-autocomplete attribute
-Turning off autocompletion
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.
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
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.
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 theirform 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.
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'.
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.
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
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
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.
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
trueif the associated controls' values have no validity problems; otherwise, returnsfalse.
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
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
trueif the associated controls' values have no validity problems; otherwise, returnsfalse.
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
submitterHTMLElement
Returns
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
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 asdisabled.
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.
Submit()
The HTMLFormElement.submit() method submits a given
form.
[Value("submit")]
public GlobalObject.Undefined Submit()
Returns
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.