-
-
Save WesleySmits/0be8b06aaecfa16007256d7c44ff74b3 to your computer and use it in GitHub Desktop.
Formdata: Usage of the FormData object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const newsletterForm = document.getElementById('newsletter-form'); | |
newsletterForm.addEventListener('submit', () => { | |
const formData = new FormData(newsletterForm); | |
const name = formData.get('name'); | |
// Append timestamp | |
formData.append('timestamp', Date.now().toString()); | |
// Delete timestamp | |
formData.delete('timestamp'); | |
// Set name | |
formData.set('name', 'John Doe'); | |
// Loop through formData | |
for (const [key, value] of formData) { | |
console.log(key, value); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment