With HTML, a reset button can be added in a form with
<input /> tag. For that, we need to specify attribute
"reset" value as
<input type="reset" value="Reset" />
And when the user clicks on the
Reset button, the form that it belongs to will reset to its original state.
- Assume that we have an E-commerce website containing login and registration form on the same page like Facebook.
- An HTML form for registration with id
registrationFormwhich will be used by a new customer coming to our website.
<form action="https://example.com/registration" method="post" id="registrationForm"> <!-- .... --> </form>
const registrationForm = document.getElementById("registrationForm"); registrationForm.reset();
This will restore the form to its original state by clearing all the form elements.
Read others post on our site MeshWorld
“Talk is cheap. Show me the code.”
~ Linus Torvalds
Happy 😄 coding
With ❤️ from 🇮🇳