0

I have written a JavaScript function that shows a text input field when a checkbox is clicked. The essence of the function is basically to change the text box display property from "none", to "block" on checkbox click. This works fine, and thus when I check the box I see the text field, and when I uncheck the box, the text box hides.

Now, I am trying to figure out how to keep the text box showing after the page is refreshed. This is where I am stuck.

Any suggestions? Thanks!

Please let me know if I need to clarify anything!

Eric
  • 11
  • 2

1 Answers1

2

Best way is to store your state in a cookie and read it after load to get back to the same state : Set cookie and get cookie with JavaScript

Community
  • 1
  • 1
Blag
  • 5,818
  • 2
  • 22
  • 45
  • Can you please provide an example? – Eric Nov 17 '15 at 20:30
  • http://stackoverflow.com/a/24103596/5546267 even with this one you need an example ? – Blag Nov 17 '15 at 20:39
  • Also, I should add - I have decided to add a "Save" button to the form which contains the checkbox scenario I speak of above, is there anyway I can use that to obtain the result I am looking for? – Eric Nov 17 '15 at 20:39
  • @Eric you don't need the 'save' , just put a set/erase cookie in the code that hide/display you input – Blag Nov 17 '15 at 20:42
  • @Eric if you still can't get it work after trying, edit your post and put your code with your test, I'll take a look ;) – Blag Nov 17 '15 at 20:51
  • Cool thanks! Much appreciated! Is doing something like local storage a better or worse option, and checking on page load whether the item is null or not? – Eric Nov 18 '15 at 17:40
  • Cookie is a local browser storage, so I don't really understand your question... ? – Blag Nov 18 '15 at 19:17