Last active
December 30, 2016 15:14
-
-
Save nicolasrenon/d41dd03688fa475644c70b5e0a64f7b6 to your computer and use it in GitHub Desktop.
Example of FormData
This file contains hidden or 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
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<title>Example of FormData</title> | |
</head> | |
<body> | |
<form name="subscription"> | |
<p><input type="text" name="first_name" placeholder="First name"></p> | |
<p><input type="text" name="last_name" placeholder="Last name"></p> | |
<p> | |
<select name="gender" id=""> | |
<option value="1">Male</option> | |
<option value="2">Female</option> | |
</select> | |
</p> | |
<button type="submit">Submit</button> | |
</form> | |
</body> | |
</html> |
This file contains hidden or 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
var form = document.querySelector('form'); | |
form.addEventListener('submit', (event) => { | |
event.preventDefault(); | |
var formData = new FormData(this); | |
formData.append('datetime', Date.now()); | |
for (var value of formData.values()) { | |
console.log(value); | |
} | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment