Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2020 06:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
form div {
margin: 5px 0;
<form name="simple-form" id="simple-form">
<label for="name-input">Name: </label>
<input required id="name-input" name="name" />
<label for="email-input">Email: </label>
<input required type="email" id="email-input" name="email" />
<button type="submit">Submit</button>
<h2>Form Output</h2>
<p id="form-output"></p>
import template from "./demo.html";
document.body.innerHTML = template;
(function () {
const output = document.getElementById("form-output");
const form = document.getElementById("simple-form");
form.onsubmit = () => false;
form.addEventListener("submit", () => {
const formData = new FormData(form);
let outputHTML = "";
for (var pair of formData.entries()) {
outputHTML += `<div>${pair[0]}: ${pair[1]}</div>`;
output.innerHTML = outputHTML;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment