Source Code:
(back to article)
Submit
Result:
Report an issue
<form id="myForm" onsubmit="onSubmit(event)"> <input type="text" name="username" value="John Doe"> <input type="email" name="email" value="john@example.com"> <input type="submit"> </form> <script> function onSubmit(event) { const form = document.getElementById('myForm'); const formData = new FormData(form); const username = formData.get('username'); const email = formData.get('email'); alert(`username: ${username}; email: ${email}`); } </script>