Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The setFormValue() method of the ElementInternals interface sets the element's submission value and state, communicating these to the user agent.
setFormValue(value) setFormValue(value, state)
valueA File, a string, or a FormData as the value to be submitted to the server.
state OptionalA File, a string, or a FormData representing the input made by the user. This allows the application to re-display the information that the user submitted, in the form that they submitted it, if required.
Note: In general, state is used to pass information specified by a user, the value is suitable for submission to a server, post sanitization. For example, if a custom element asked a user to submit a date, the user might enter "3/15/2019". This would be the state. The server expects a date format of 2019-03-15, the date in this format would be passed as the value.
Undefined.
NotSupportedError DOMException
Thrown if the element does not have its formAssociated property set to true.
In the following example, a checkbox custom element sets on as the value to send to the server, and checked as the state.
this.internals_.setFormValue("on", "checked");
| Specification |
|---|
| HTML> # dom-elementinternals-setformvalue> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
setFormValue |
77 | 79 | 98 | 64 | 16.4 | 77 | 98 | 55 | 16.4 | 12.0 | 77 | 16.4 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/setFormValue