I have the following which works fine for text inputs, textareas and selects with the class 'stored'.
$(function() {
$.each($('.stored'), function() {
if(localStorage[$(this).attr('name')]) {
$(this).val(localStorage[$(this).attr('name')]);
}
});
$('.stored').on('change', function() {
localStorage[$(this).attr('name')] = $(this).val(), $(this).find('option:selected').val();
});
});
To store radio buttons or checkboxes with the class 'stored' in localStorage I've tried to extend that on change function with several ways such as:
localStorage[$(this).attr('name')] = $(this).val(), $(this).find('option:selected').val(), this.checked.val();
But no can do!
Then I tried to seperate it with the following, but also nothing
if ($('.stored').is(':checked')) {
localStorage[$(this).attr('name')] = $(this).val();
};
So how to do this exactly? I've created a pen with this all.
http://codepen.io/gentlemedia/pen/ORgQyr/
Thanks!