Is there a simple way to display my local storage with document.write or document.innerHTML methods? It's being stored on 1 page, trying to display on separate. I'm new to js and just unsure how to build the syntax of those methods with how I'm storing it(if possible).
$('form').submit(function() {
var person = $("#FirstName").val() + "." + $('#LastName').val();
$('input, select, textarea').each(function() {
var value = $(this).val(),
name = $(this).attr('name');
localStorage[person + "." + name] = value;
window.location.href = "Confirmation.html";
console.log('stored key: '+name+' stored value: '+value);
});
});
heres the whole if it helps: /
Is there a simple way to display my local storage with document.write or document.innerHTML methods? It's being stored on 1 page, trying to display on separate. I'm new to js and just unsure how to build the syntax of those methods with how I'm storing it(if possible).
$('form').submit(function() {
var person = $("#FirstName").val() + "." + $('#LastName').val();
$('input, select, textarea').each(function() {
var value = $(this).val(),
name = $(this).attr('name');
localStorage[person + "." + name] = value;
window.location.href = "Confirmation.html";
console.log('stored key: '+name+' stored value: '+value);
});
});
heres the whole if it helps: http://jsfiddle.net/EUWFN/
Share Improve this question asked Oct 29, 2013 at 19:21 user1user1 3572 gold badges13 silver badges22 bronze badges2 Answers
Reset to default 14As local storage is Object, you can go trough all it keys and get in values in simple way
for (var key in localStorage) {
console.log(key + ':' + localStorage[key]);
}
To print it to the screen you can use something like this:
var output = '';
for (var key in localStorage) {
output = output+(key + ':' +localStorage[key])+'\n';
}
$('#DivToPrintOut').html(output);
If you're using Chrome, press F12 for the Developers Tools.
In the Console type localStorage
and press enter.
Or in your js code put console.log(localStorage);
.
In the console, click on the little triangle next to line that begins with Storage
.
Or in Dev Tools:
- click on the
Resources
tab at the top - click on the little triangle next to
Local Storage
in the frame on the left