Class HTMLTextAreaElement
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The HTMLTextAreaElement interface provides properties and methods for manipulating the layout and presentation of textarea elements.
[Value("HTMLTextAreaElement")]
public class HTMLTextAreaElement : HTMLElement
- Inheritance
-
HTMLTextAreaElement
- Inherited Members
Remarks
Constructors
HTMLTextAreaElement()
public HTMLTextAreaElement()
Properties
Autocomplete
The autocomplete property of the HTMLTextAreaElement interface indicates whether the value of the control can be automatically completed by the browser. It reflects the <textarea> element's autocomplete attribute.
[Value("autocomplete")]
public string Autocomplete { get; set; }
Property Value
- string
A string representing the value of the
autocompleteattribute ("on","off", or a<token-list>) or the empty string ("") if unspecified.
Remarks
-textarea
-HTML autocomplete attribute
-ARIA aria-autocomplete attribute
-Turning off autocompletion
Cols
The cols property of the HTMLTextAreaElement interface is a positive integer representing the visible width of the multi-line text control, in average character widths. It reflects the <textarea> element's cols attribute.
[Value("cols")]
public ulong Cols { get; set; }
Property Value
- ulong
A positive integer. Defaults to
20.
Remarks
DefaultValue
The defaultValue property of the HTMLTextAreaElement interface represents the default text content of this text area. Getting and setting this value is equivalent to getting and setting TextContent on the {{htmlelement("textarea")}}.
[Value("defaultValue")]
public string DefaultValue { get; set; }
Property Value
- string
A string.
Remarks
DirName
The dirName property of the HTMLTextAreaElement interface is the directionality of the element. It reflects the value of the {{htmlelement("textarea")}} element's dirName attribute. This property can be retrieved or set.
[Value("dirName")]
public string DirName { get; set; }
Property Value
- string
A string. The direction of the element.
Remarks
The dirname attribute controls how the element's directionality is submitted. When included, the form control will submit with two name/value pairs: the first being the name and value of the <textarea>, and the second being the value of the dirname attribute as the name, with a value of ltr or rtl as set by the browser.
Disabled
The disabled property of the HTMLTextAreaElement interface indicates whether this multi-line text control is disabled and cannot be interacted with. It reflects the {{htmlelement("textarea")}} element's disabled attribute. When false, this textarea may still be disabled if its containing element, such as a fieldset, is disabled.
[Value("disabled")]
public bool Disabled { get; set; }
Property Value
- bool
A boolean.
Remarks
Form
The form read-only property of the HTMLTextAreaElement interface returns an HTMLFormElement object that owns this {{htmlelement("textarea")}}, or null if this textarea is not owned by any form.
[Value("form")]
public HTMLFormElement? Form { get; }
Property Value
- HTMLFormElement
An HTMLFormElement or
null.
Remarks
-HTMLTextAreaElement
-HTMLFormElement
-textarea
-HTML form attribute
-HTML forms guide
Labels
The HTMLTextAreaElement.labels read-only property returns
a NodeList of the {{HTMLElement("label")}} elements associated with the
textArea element.
[Value("labels")]
public NodeList Labels { get; }
Property Value
- NodeList
A NodeList containing the
<label>elements associated
with the<textArea>element.
Remarks
MaxLength
The maxLength property of the HTMLTextAreaElement interface indicates the maximum number of characters (in {{glossary("UTF-16", "UTF-16 code units")}}) allowed to be entered for the value of the {{HTMLElement("textarea")}} element, and the maximum number of characters allowed for the value to be valid. It reflects the element's maxlength attribute. -1 means there is no limit on the length of the value.
[Value("maxLength")]
public long MaxLength { get; set; }
Property Value
- long
A number representing the element's
maxlengthif present, or-1.
Remarks
NOTE
Browsers generally prevent users from entering more characters than the
maxlengthattribute allows. Should the length be longer, the element is considered invalid and the ValidityState object's TooLong property will betrue.
MinLength
The minLength property of the HTMLTextAreaElement interface indicates the minimum number of characters (in {{glossary("UTF-16", "UTF-16 code units")}}) required for the value of the {{HTMLElement("textarea")}} element to be valid. It reflects the element's minlength attribute. -1 means there is no minimum length requirement.
[Value("minLength")]
public long MinLength { get; set; }
Property Value
- long
A number representing the element's
minlengthif present or-1.
Remarks
NOTE
If the textarea has a value, and that value has fewer characters than the
minlengthattribute requires, the element is considered invalid and the ValidityState object's TooShort property will betrue.
Name
The name property of the HTMLTextAreaElement interface indicates the name of the {{HTMLElement("textarea")}} element. It reflects the element's name attribute.
[Value("name")]
public string Name { get; set; }
Property Value
- string
A string representing the element's name.
Remarks
Placeholder
The placeholder property of the HTMLTextAreaElement interface represents a hint to the user of what can be entered in the control. It reflects the {{htmlelement("textarea")}} element's placeholder attribute.
[Value("placeholder")]
public string Placeholder { get; set; }
Property Value
- string
A string.
Remarks
ReadOnly
The readOnly property of the HTMLTextAreaElement interface indicates that the user cannot modify the value of the control. Unlike the Disabled attribute, the readonly attribute does not prevent the user from clicking or selecting in the control. It reflects the textarea element's readonly attribute.
[Value("readOnly")]
public bool ReadOnly { get; set; }
Property Value
- bool
A boolean.
Remarks
-textarea
-Disabled
-:read-only pseudo-class
Required
The required property of the HTMLTextAreaElement interface specifies that the user must fill in a value before submitting a form. It reflects the {{htmlelement("textarea")}} element's required attribute.
[Value("required")]
public bool Required { get; set; }
Property Value
- bool
A boolean.
Remarks
Rows
The rows property of the HTMLTextAreaElement interface is a positive integer representing the visible text lines of the text control. It reflects the <textarea> element's rows attribute.
[Value("rows")]
public ulong Rows { get; set; }
Property Value
- ulong
A positive integer. Defaults to
2.
Remarks
SelectionDirection
The selectionDirection property of the HTMLTextAreaElement interface specifies the current direction of the selection. The possible values are "forward", "backward", and "none". The forward value indicates the selection was performed in the start-to-end direction of the current locale, with backward indicating the opposite direction. The none value occurs if the direction is unknown. It can be used to both retrieve and change the direction of the <textarea>s selected text.
[Value("selectionDirection")]
public string SelectionDirection { get; set; }
Property Value
- string
A string;
"forward","backward", or"none".
Remarks
Setting the selectionDirection to a new value fires the HTMLTextAreaElement.Selectionchange and Select() events.
-textarea
-HTMLTextAreaElement
-SelectionStart
-SelectionEnd
-TextLength
-Select()
-SetSelectionRange(ulong, ulong, string)
-SetRangeText(string)
-SelectionDirection
-Selection
-{{cssxref("::selection")}} pseudo-element
SelectionEnd
The selectionEnd property of the HTMLTextAreaElement interface specifies the end position of the current text selection in a {{HTMLElement("textarea")}} element. It is a number representing the last index of the selected text. It can be used to both retrieve and set the index of the end of a <textarea>s selected text.
[Value("selectionEnd")]
public ulong SelectionEnd { get; set; }
Property Value
- ulong
A non-negative number.
Remarks
When nothing is selected, the value of both the SelectionStart and selectionEnd is the position of the cursor (caret) inside the <textarea> element.
Setting selectionEnd to a value less than the current value of SelectionStart updates both the selectionEnd and selectionStart properties to that value. If both value are less than 0, both properties are set to the TextLength property value.
The property value can be retrieved and set without the <textarea> having focus, but the element does need to have focus for the {{cssxref("::selection")}} pseudo-element to match the selected text.
Setting the selectionEnd to a new value fires the HTMLTextAreaElement.Selectionchange and Select() events.
-textarea
-HTMLTextAreaElement
-SelectionStart
-SelectionDirection
-TextLength
-HTMLTextAreaElement.SelectionChange event
-Select()
-SetSelectionRange(ulong, ulong, string)
-SetRangeText(string)
-SelectionEnd
-Selection
-{{cssxref("::selection")}} pseudo-element
SelectionStart
The selectionStart property of the HTMLTextAreaElement interface specifies the start position of the current text selection in a {{HTMLElement("textarea")}} element. It is a number representing the beginning index of the selected text. It can be used to both retrieve and set the start of the index of the beginning of a <textarea>s selected text.
[Value("selectionStart")]
public ulong SelectionStart { get; set; }
Property Value
- ulong
A non-negative number.
Remarks
When nothing is selected, the value of both the selectionStart and SelectionEnd is the position of the cursor (caret) inside the <textarea> element.
Setting selectionStart to a value greater than the current value of SelectionEnd updates both the selectionStart and selectionEnd properties to that value. If that value is equal to or greater than the TextLength, both properties are both set to the textLength property value.
The property value can be retrieved and set without the <textarea> having focus, but the element does need to have focus for the {{cssxref("::selection")}} pseudo-element to match the selected text.
Setting the selectionStart to a new value fires the HTMLTextAreaElement.Selectionchange and Select() events.
-textarea
-HTMLTextAreaElement
-SelectionEnd
-SelectionDirection
-TextLength
-Select()
-SetSelectionRange(ulong, ulong, string)
-SetRangeText(string)
-SelectionStart
-Selection
-{{cssxref("::selection")}} pseudo-element
TextLength
The textLength read-only property of the HTMLTextAreaElement interface is a non-negative integer representing the number of characters, in {{glossary("UTF-16", "UTF-16 code units")}}, of the {{htmlelement("textarea")}} element's value. It is a shortcut of accessing {{jsxref("String/length", "length")}} on its HTMLTextAreaElementvalue property.
[Value("textLength")]
public ulong TextLength { get; }
Property Value
- ulong
A non-negative integer.
Remarks
Type
The type read-only property of the HTMLTextAreaElement interface returns the string "textarea".
[Value("type")]
public string Type { get; }
Property Value
- string
The string
"textarea".
Remarks
ValidationMessage
The validationMessage read-only property of the HTMLTextAreaElement interface returns a string representing a localized message that describes the validation constraints that the {{htmlelement("textarea")}} control does not satisfy (if any). This is the empty string if the control is not a candidate for constraint validation (WillValidate is false), or it satisfies its constraints.
[Value("validationMessage")]
public string ValidationMessage { get; }
Property Value
- string
A string.
Remarks
If the <textarea> element is a candidate for constraint validation (willValidate is true) and the constraints are not met (the Validity object's valid property is false), the value is the error message that would be shown to the user during validation.
-textarea
-HTMLTextAreaElement
-WillValidate
-Validity
-CheckValidity()
-ReportValidity()
-SetCustomValidity(string)
-Learn: Client-side form validation
-Guide: Constraint validation
-CSS :valid and :invalid pseudo-classes
Validity
The validity read-only property of the HTMLTextAreaElement interface returns a ValidityState object that represents the validity states this element is in.
[Value("validity")]
public ValidityState Validity { get; }
Property Value
- ValidityState
A ValidityState object.
Remarks
Value
The value property of the HTMLTextAreaElement interface represents the value of the {{htmlelement("textarea")}} element as a string, which is an empty string if the widget contains no content. It returns or sets the raw value contained in the control.
[Value("value")]
public string Value { get; set; }
Property Value
Remarks
WillValidate
The willValidate read-only property of the HTMLTextAreaElement interface indicates whether the {{htmlelement("textarea")}} element is a candidate for constraint validation. It is false if any conditions bar it from constraint validation, such as when its Disabled or ReadOnly property is true.
[Value("willValidate")]
public bool WillValidate { get; }
Property Value
- bool
A boolean value.
Remarks
Wrap
The wrap property of the HTMLTextAreaElement interface indicates how the control should wrap the value for form submission. It reflects the <textarea> element's wrap attribute. Note that the "hard" value only has an effect when the Cols attribute is also set.
[Value("wrap")]
public string Wrap { get; set; }
Property Value
Remarks
Methods
CheckValidity()
The checkValidity() method of the HTMLTextAreaElement interface returns a boolean value which indicates if the element meets any constraint validation rules applied to it. If false, the method also fires an HTMLElementinvalid event on the element. 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 element's value has no validity problems; otherwise, returnsfalse.
Remarks
NOTE
An HTML {{htmlelement("textarea")}} element with a non-null ValidationMessage is considered invalid, will match the CSS {{cssxref(":invalid")}} pseudo-class, and will cause
checkValidity()to return false. Use the SetCustomValidity(string) method to set the ValidationMessage to the empty string to set the Validity state to be valid.
-ReportValidity()
-textarea
-form
-Learn: Client-side form validation
-Guide: Constraint validation
-CSS :valid and :invalid pseudo-classes
ReportValidity()
The reportValidity() method of the HTMLTextAreaElement interface performs the same validity checking steps as the CheckValidity() method. In addition, if the HTMLElementinvalid event is not canceled, the browser displays the problem to the user.
[Value("reportValidity")]
public bool ReportValidity()
Returns
- bool
Returns
trueif the element's value has no validity problems; otherwise, returnsfalse.
Remarks
-CheckValidity()
-textarea
-form
-Learn: Client-side form validation
-Guide: Constraint validation
-CSS :valid and :invalid pseudo-classes
Select()
The select() method of the HTMLTextAreaElement interface selects the entire contents of the {{htmlelement("textarea")}} element. In addition, the Select() event is fired. The select() method does not take any parameters and does not return a value.
[Value("select")]
public GlobalObject.Undefined Select()
Returns
Remarks
-textarea
-HTMLTextAreaElementselect event
-AddEventListener(string, Action?, Union26)
-CSS {{cssxref("::selection")}} pseudo-element
SetCustomValidity(string)
The setCustomValidity() method of the HTMLTextAreaElement interface sets the custom validity message for the {{htmlelement("textarea")}} element. Use the empty string to indicate that the element does not have a custom validity error.
[Value("setCustomValidity")]
public GlobalObject.Undefined SetCustomValidity(string error)
Parameters
errorstring
Returns
Remarks
-textarea
-HTMLTextAreaElement
-Validity
-CheckValidity()
-ReportValidity()
-Form validation.
-Learn: Client-side form validation
-Guide: Constraint validation
-CSS :valid and :invalid pseudo-classes
SetRangeText(string)
The setRangeText() method of the HTMLTextAreaElement interface replaces a
range of text in a textarea element with new text passed as the argument.
[Value("setRangeText")]
public GlobalObject.Undefined SetRangeText(string replacement)
Parameters
replacementstring
Returns
Remarks
Additional optional parameters include the start of the section of text to change, the end of the section, and a keyword defining what part of the <textarea> should be selected after the text is updated. If the startSelection and endSelection arguments are not provided, the range is assumed to be the selection.
The final argument determines how the selection will be set after the text has been replaced. The possible values are "select", which selects the newly inserted text, "start", which moves the selection to just before the inserted text, "end", which moves the selection to just after the inserted text, or the default, "preserve", which tries to preserve the selection.
In addition, the Select() and HTMLTextAreaElement.Selectionchange events are fired.
-textarea
-HTMLTextAreaElement
-Select()
-SetSelectionRange(ulong, ulong, string)
-TextLength
-Selection
-{{cssxref("::selection")}} pseudo-element
SetRangeText(string, ulong, ulong, SelectionMode)
The setRangeText() method of the HTMLTextAreaElement interface replaces a
range of text in a textarea element with new text passed as the argument.
[Value("setRangeText")]
public GlobalObject.Undefined SetRangeText(string replacement, ulong start, ulong end, SelectionMode selectionMode = SelectionMode.Select)
Parameters
replacementstringstartulongendulongselectionModeSelectionMode
Returns
Remarks
Additional optional parameters include the start of the section of text to change, the end of the section, and a keyword defining what part of the <textarea> should be selected after the text is updated. If the startSelection and endSelection arguments are not provided, the range is assumed to be the selection.
The final argument determines how the selection will be set after the text has been replaced. The possible values are "select", which selects the newly inserted text, "start", which moves the selection to just before the inserted text, "end", which moves the selection to just after the inserted text, or the default, "preserve", which tries to preserve the selection.
In addition, the Select() and HTMLTextAreaElement.Selectionchange events are fired.
-textarea
-HTMLTextAreaElement
-Select()
-SetSelectionRange(ulong, ulong, string)
-TextLength
-Selection
-{{cssxref("::selection")}} pseudo-element
SetSelectionRange(ulong, ulong, string)
The setSelectionRange() method of the HTMLTextAreaElement interface sets the start and end positions of the current text selection, and optionally the direction, in a {{HTMLElement("textarea")}} element. This updates the selection state immediately, though the visual highlight only appears when the element is focused. The direction indicates the in which selection should be considered to have occurred; for example, that the selection was set by the user clicking and dragging from the end of the selected text toward the beginning. In addition, the Select() and HTMLTextAreaElement.Selectionchange events are fired.
[Value("setSelectionRange")]
public GlobalObject.Undefined SetSelectionRange(ulong start, ulong end, string direction = null)
Parameters
Returns
Remarks
This method updates the SelectionStart, SelectionEnd, and SelectionDirection properties immediately, regardless of focus state. The visual selection highlight requires the element to be focused.
NOTE
While
setSelectionRange()updates the selection properties immediately, the visual selection highlight only appears when the<textarea>is focused. Focusing the element will also fire aselectionchangeevent.
To select all of the text of an <textarea> element, use the Select() method.
-textarea
-HTMLTextAreaElement
-Select()
-TextLength
-Selection
-{{cssxref("::selection")}} pseudo-element