Skip to content

TIL form elements have a formdata event

β€’ ~1 min read

If you're using FormData from a form, you can stop listening for submit events!

Whoa, this is neat. Check out the FormDataEvent on MDN!

You don’t need to construct an instance of FormData if instead of listening for submit events you listen for formdata events!

// modified from MDN docs for brevity
formElem.addEventListener(
	"formdata",
	(e) => {
		const formData = e.formData;
		console.log(
			"formdata fired",
			formData,
		);
	},
);

It even has great browser support!

Share this post

πŸ“§ Email