What is the difference between clearing and reselling a web form?

I want to reset the value of a webpage using the JavaScript reset() function. Which operation is primarily performed by JavaScript: reset or clear? And what is the difference between the two?

Also, how can I get the value using the reset function?

+4
source share
3 answers

Clear Reset

Cleaning the form makes all input fields empty, deselects the checkboxes, deselects the selection, etc .; whereas resetting the form returns all changes.

For instance:

 <input type="text" name="name" value="Timothy" /> <input type="reset" value="Reset" /> 

This creates an input field with a value of Timothy . Say the user then changes the value to Berners-Lee . If the user presses the Reset button, the Berners-Lee value will reset to Timothy .

Removing the fields will change the value attribute of the input field to an empty string as follows:

 <input type="text" name="name" value="" /> 

You can change the value attribute using JavaScript.

Get value

If you want to get (or set) a value for a field using JavaScript, try reading them:

+14
source

The reset function is executed as if you had input type="reset" in the form and clicked it.

It will reset the values ​​in all fields in the form to the value that they had when loading the page.

If you have a text box like this:

 <input type="text" name="info" value="Hejsan" /> 

calling reset will return the value of "Hejsan" back to the text box.

If you did not specify a value (or did not select an option in the select field), it is reset for an empty value (or for the select field the first option).

The reset function cannot be used to retrieve any values.

+3
source

Edit: I changed my original answer to this thanks to Dave's comment. It looks like he also posted the answer while I changed my answer, so he deserves an “accepted” answer.

Resetting a form resets the original values ​​of all fields in the form. If there was no value, it will clear the field; if there is a value, it will return the "reset" field to this value.

When you clear a form, you essentially remove ALL values ​​from the form. JavaScript doesn’t have a “crisp” function, so you have to go through each field and clear them manually.

To answer your question, you just want to "reset" the form using the reset () function, not clear the form.

+1
source

All Articles