Form reset() Method in javaScript
Form reset after clicking the reset button or you can use this function after the form submits successfully.
let see we have a form:
<form action="/" id="formId>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="button" onclick="doSubmit" value="Submit">
<button type="button" onclick="resetAll()">Reset</button>
</form>
| <script> |
|
function resetAll(){ document.getElementById("formId").reset();
//if need to reload the page } </script> |
No comments