I\'m trying to store via local storage all form field values (under the input id) like so localStorage.setItem(\"input id\", fieldvalue); when a user clicks the
If you want to rely on jQuery this can help you:
$('#save').on('click', function(){
$('input[type="text"]').each(function(){
var id = $(this).attr('id');
var value = $(this).val();
localStorage.setItem(id, value);
});
});
$('#load').on('click', function(){
$('input[type="text"]').each(function(){
var id = $(this).attr('id');
var value = localStorage.getItem(id);
$(this).val(value);
});
});
I would recommend to avoid inline-js, so I updated to code to use .on() for attaching the click-handler to the two buttons.
Demo
Reference:
.each()