Home>Article>Web Front-end> How to clear all inputs in HTML form?

How to clear all inputs in HTML form?

PHPz
PHPz forward
2023-09-01 11:21:09 1131browse

Using HTML forms, you can easily obtain user input. Use the

tag to add form elements to capture user input. Different types of form elements include text inputs, radio button inputs, submit buttons, etc.

TagHelps you get user input by using the type attribute. To clear all input in an HTML form, use thetag with the type attribute reset.

How to clear all inputs in HTML form?

Example 1

The following example demonstrates how to clear all input in an HTML form.

In this example, we will use document.getElementId to clear the text in the text field.

      Remove HTML 

When we click the clear button, the text in the input (text area) field will be cleared.

The Chinese translation of

Example 2

is:

Example 2

The following example demonstrates how to clear all input in an HTML form.

In this example, we will use the reset button to clear the text in the text field.

      Clear all the input in HTML forms 

When we click the clear button, the text in the input (text area) field will be cleared.

Example 3

The following example demonstrates how to clear all input in an HTML form.

In this example, we are going to use onclick() method to clear the text in the text field.

      Clear all the input in HTML forms 
The Chinese translation of

Example 4

is:

Example 4

You can try running the following code to clear all inputs in the HTML form -

   
Student Name:

Student Subject:

Once the reset button is clicked, the form will be cleared.

The above is the detailed content of How to clear all inputs in HTML form?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete