How To Retain Radio Input State On Page Refresh
i have a form on which i need to store the state of all radio buttons if a user submit the form with errors (which in case the page would refresh). I want to achieve something quit
Solution 1:
You could store it's state within local storage and restore it after each page load.
Little example on storing the value:
$('#myCheckbox').click(function () {
localStorage['my.checkbox'] = this.checked;
});
Restore it:
$('#myCheckbox').prop('checked', localStorage['my.checkbox'] == 'true');
Solution 2:
Maybe you store the information in the session token or in a session cookie. If you use html5 components, you might try to use html local storage.
Solution 3:
you just need to update the code
$(function(){
$('.example input[type="radio"]').each(function(){
$(this).attr("checked",$(this).checked());
});
It will save the property of radio button as user has selected for the radio button.
Post a Comment for "How To Retain Radio Input State On Page Refresh"