1

I want to know if there is a way to keep text in the input fields if a user hit the refresh button while typing something in a form.

<form>
    <input type="text" name="aaa"/>
</form>

I want to keep this text in the input field after refresh the page. Is it possible? Please help me anyone to give a suitable answer or reference. Thanks in advance..

Nirob Hasan
  • 55
  • 1
  • 9

2 Answers2

2

This is surly possible with some javascript. You can track all changes to the input field and on every change, store the current value of the input field in SessionStorage or LocalStorage. And you have to install an onload handler that writes the stored values back to the input field.

Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
Ridcully
  • 23,362
  • 7
  • 71
  • 86
2

You can't force the browser on itself to do this. Furthermore, your server-side scripting languages are useless here as you want it to work after a refresh of the page, which means that there's no server-side knowledge of the values of the fields. So you'll need to use client-side scripting like Javascript to do this. Store the values as soon as they change in cookies or in sessions and fill them in the form from cookies or sessions.

Paul Fleming
  • 24,238
  • 8
  • 76
  • 113
bartlaarhoven
  • 825
  • 2
  • 8
  • 21