Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. FormDataEvent
  4. formData

FormDataEvent: formData property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨September 2021⁩.

TheformData read-only property of theFormDataEventinterface contains theFormData object representing the data contained inthe form when the event was fired.

Value

AFormData object.

Examples

js
// grab reference to formconst formElem = document.querySelector("form");// submit handlerformElem.addEventListener("submit", (e) => {  // on form submission, prevent default  e.preventDefault();  // construct a FormData object, which fires the formdata event  new FormData(formElem);});// formdata handler to retrieve dataformElem.addEventListener("formdata", (e) => {  console.log("formdata fired");  // Get the form data from the event object  let data = e.formData;  for (const value of data.values()) {    console.log(value);  }  // submit the data via XHR  const request = new XMLHttpRequest();  request.open("POST", "/formHandler");  request.send(data);});

Specifications

Specification
HTML
# the-formdataevent-interface:dom-formdataevent-formdata-2

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp