Skip to content

Instantly share code, notes, and snippets.

@techb
Created June 28, 2023 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save techb/d9fb80fe446efcaa22fc8fce8532c26a to your computer and use it in GitHub Desktop.
Save techb/d9fb80fe446efcaa22fc8fce8532c26a to your computer and use it in GitHub Desktop.
// Yoink: https://www.javascripttutorial.net/web-apis/javascript-formdata/
const btn = document.querySelector('#submit-btn-id');
const form = document.querySelector('#my-form-id');
btn.addEventListener('click', (e) => {
// prevent the form from submitting
// or uncomment the debugger statment below for a breakpoint
// if needing to also send the data for testing
e.preventDefault();
// show the form values
const formData = new FormData(form);
const values = [...formData.entries()];
console.log(values);
// comment out the preventDefault and uncomment below to sue breakpoints instead
// debugger;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment