javascript - Local Storage function always storing radio button value -
my local storage function stores radio button value of "3" in local storage regardless of selection made , don't have idea of why. every other element stores properly.
please see fiddle show problem: http://jsfiddle.net/3u7xj/148/
my function:
$('input, select, textarea').each(function() { var value = $(this).val(); var name = $(this).attr('name'); if ($(this).hasclass('checkers')) { value = $(this).is(":checked"); if (value) { value = 'on'; } else { value = 'off'; } } if (this.name.match(/^multiselect_/)) {//removes buggy append return false; } console.log('saving'); console.log(name + ':' + value); survey[name] = value; }); if (localstorage.getobj('surveys') !== null) { surveys = localstorage.getobj('surveys'); } surveys[$('#firstname').val() + '.' + $('#lastname').val()] = survey; //store in big list localstorage.setobj('surveys', surveys);
the radio buttons have same name, because they're radio buttons, , have value. code gets value of each of radio buttons , saves each value same property of "survey" object. last 1 sees 1 saved.
you'll have add code you've got checkboxes:
if (!$(this).is(':radio') || this.checked) survey[name] = value;
Comments
Post a Comment