Category: Vanilla Javascript

Added: 25th of October 2020

Viewed: 743 times

Clear all form fields using Javascript

What does the script do
The simple code below clears a webform by using the input type button and onclick event that calls the clear_form function and clears the form fields, by getting the form id element.

<form id="form">
First Name: <input type="text" name="first_name" value="">
Surname: <input type="text" name="first_name" value="">
<input type="button" onclick="clear_form()" value="Clear Form"> </form>

<script type="text/javascript">
function clear_form()
{
// Clear the input fields
document.getElementById("form").reset();
}
</script>





Other Tips & Tutorials

Vanilla Javascript

Display date and time using Javascript

Posted: 25th of July 2021

Views: 75

Vanilla Javascript

Clear all form fields using Javascript

Posted: 25th of October 2020

Views: 743

Vanilla Javascript

Generate a random number between 1 and 5 using Math.floor and Math.random commands in Javascript

Posted: 22nd of October 2018

Views: 1680

Vanilla Javascript

Using document.getElementByID() in javascript to send form data

Posted: 15th of October 2018

Views: 1504

Vanilla Javascript

Using document write() in javascript.

Posted: 14th of October 2018

Views: 1830