Last active
June 11, 2022 21:25
-
-
Save beardedtim/1d24db1c9e7255fc435687799d8cb685 to your computer and use it in GitHub Desktop.
Basic Form in JS
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Input Example</title> | |
</head> | |
<body> | |
<form> | |
<div class="input_group"> | |
<label for="input"> | |
Some Input | |
</label> | |
<input id="input" name="some-input" /> | |
</div > | |
<button type="submit"> | |
submit | |
</button> | |
</form> | |
<script> | |
window.addEventListener('load', () => { | |
const form = document.querySelector('form') | |
form.addEventListener('submit', e => { | |
const formData = new FormData(form) | |
const value = formData.get('some-input') | |
// or | |
const valueFromHTML = document.getElementById('input').value | |
}) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment