Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Unable to store radio button value in localStorage Reply To: Unable to store radio button value in localStorage

#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();
});

});