Category: Vanilla Javascript

Added: 25th of October 2020

Viewed: 1083 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

Other Tips & Tutorials

Vanilla Javascript

Display date and time using Javascript

Posted: 25th of July 2021

Views: 235

Vanilla Javascript

Clear all form fields using Javascript

Posted: 25th of October 2020

Views: 1083

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: 1839

Vanilla Javascript

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

Posted: 15th of October 2018

Views: 1683

Vanilla Javascript

Using document write() in javascript.

Posted: 14th of October 2018

Views: 2028