JavaScript

How to reset a form with JavaScript

In this tutorial you will learn how to reset a form with JavaScript using the reset() method, as shown in the example below:
 

How to reset a form with JavaScript
<!DOCTYPE html>
<html>
	<head>
		<title>Reset a form</title>
		<script>
		   function resetForm() {
			   document.getElementById("frm").reset();
		   }
		</script>
	</head>
	<body>
		<form action="run.php" method="post" id="frm">
			<p><label>Firstname:</label> <input type="text" name="firstname"></p>
			<p><label>Lastname:</label> <input type="text" name="lastname"></p>
			<p><label>Address:</label> <input type="text" name="address"></p>
		</form>
		<button type="button" onclick="resetForm();">Reset the form</button>
	</body>
</html>
Result
Reset the form

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *