function getObjectFromForm(formSelector) { document.querySelector(formSelector) .addEventListener("submit", e => { e.preventDefault(); const data = Object.fromEntries(new FormData(e.target)); // then do what you want with data or JSON.stringify(data) }); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter