I have a <form>
with a few radio buttons groups:
<form>
Group 1:
<input type='radio' name='a' value='1'>
<input type='radio' name='a' value='2'>
<input type='radio' name='a' value='3'><br>
Group 2:
<input type='radio' name='b' value='1'>
<input type='radio' name='b' value='2'>
<input type='radio' name='b' value='3'>
</form>
How to save, on each selection change event, everything to localStorage
, and then on page reload (e.g. after we close and reopen the browser) reload the previously selected items?
All what I think of for this seems unnecessarily complex.
We probably have to assign a listener to event "radio button is selected" or should we detect this simply with "change" event?
NB: This solves the similar problem for <input type="text">
: Auto-save all inputs value to localStorage and restore them on page reload
Maybe is there an easier way:
Can we serialize a whole <form>
state (input values, selected radio buttons, etc.) into localStorage
, and easily restore it, without jQuery? (without having to write specific code for text inputs, other code for radio buttons, other code for checkboxes, etc.)