Home › Forums › JavaScript › Unable to store radio button value in localStorage › Reply To: Unable to store radio button value in localStorage
September 28, 2016 at 4:43 pm
#245990
gentlemedia
Participant
I’ve got it solved via another forum with the following addition to the snippet
$(function() {
$.each($('.stored'), function() {
if(localStorage[$(this).attr('name')]) {
if ($(this).is(':radio')) {
if($(this).val() == localStorage[$(this).attr('name')]) {
$(this).prop('checked', true);
}
} else {
$(this).val(localStorage[$(this).attr('name')]);
}
}
});
$('.stored').on('change', function() {
localStorage[$(this).attr('name')] = $(this).val(), $(this).find('option:selected').val();
});
});