Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Form Events</title> </head> <body> <form id="userForm"> <input type="text" id="username" name="username" placeholder="Username"> <input type="email" id="email" name="email" placeholder="Email"> <button type="submit">Submit</button> <button type="reset">Reset</button> </form> <script> const form = document.getElementById('userForm'); form.addEventListener('submit', (event) => { event.preventDefault(); alert('Form submitted!'); // Perform form validation or data processing here }); form.addEventListener('reset', () => { alert('Form reset!'); }); </script> </body> </html>