Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML - input value kept after Refresh

Usually, when a refresh is made on an HTML page, the values for input fields are kept (unless you do Ctrl+F5).

Is there a header or other type of setting than can change this behavior, without chaging anything on the form or input itself?

I have a site where the input value is not kept after a page refresh in Production. However I do not have this behavior when I test this code on my local machine.

like image 779
JB Hurteaux Avatar asked Nov 25 '09 20:11

JB Hurteaux


People also ask

How do I keep my data after refreshing page in HTML?

The easiest way to reload the current page without losing form data, use WebStorage where you have -persistent storage (localStorage) or session-based (sessionStorage) which remains in memory until your web browser is closed. window. onload = function() { var name = localStorage.

How do you keep value after page reloading?

To store the form data in JavaScript localStorage, we'll use the setItem() method. It stores the data in the localStorage object and takes the key and value parameters as input. The parameters can be later used to retrieve the data when the browser reloads the page or a new session is initiated.

How to keep input value after refresh JavaScript?

To retain the selected value in the dropdown on refresh, sessionStorage is used to store the value within the user's browser. First, the values have to be set using sessionStorage.


1 Answers

If you set the attribute autocomplete=off, the content will never be stored.

Alternatively, there's a plethora of ways to accomplish this with javascript, depending on exactly what you want to accomplish, whether it be clearing the whole form (use the reset() method), or resetting the single field.

like image 155
McPherrinM Avatar answered Nov 01 '22 21:11

McPherrinM