snippet Thursday 28 March 2024
Author
Eric Wallen
I have seen a good many of people try to clear each form input after submission one value at a time. Although this is a very short code example I think it's important to know that you can clear and entire form by selecting the id attached to the form tag.
ocument.getElementById('my-form').reset()
document
.getElementById("my-form")
.addEventListener("submit", function(event) {
event.preventDefault();
document.getElementById("my-form").reset();
});
<form id="my-form">
<input placeholder="name" /> <input placeholder="email" />
<button type="submit">Submit</button>
</form>