Snippets

Reset a Form using JavaScript

Posted by I. B. Gd Pramana A. Putra, 07 Aug 22, last updated 07 Aug 22

To reset a form with JavaScript, we can use reset() method.

This is the example of how to reset a form using JavaScript:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Reset Form Using jQuery</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
function resetForm() {
    document.getElementById("ourForm").reset();
}
</script>
</head>
<body>
    <form action="/action.php" method="post" id="ourForm">
        <label>First Name:</label>
        <input type="text" name="first-name">
        <input type="submit" value="Submit">
    </form>
    <br>
    <button type="button" onclick="resetForm();">Custom Reset Button</button>
</body>
</html>

I love sharing code snippets as most of the time, a quick code example is what we're looking for instead of long-written articles. If you think my code snippets are helpful and save you a lot of time, please consider buying me a cup of coffee :)

Support me via · paypal · buymeacoffee · ko-fi · trakteer
Contributed Snippets
Answer & Responses
    No comments yet

Wanna write a response?

You have to login before write a comment to this post.