//array to store values
var stores = Array();
//input field text
var inputField = document.getElementById('inputString');
//clear the storage
function clearStorage() {
//clear the storage
stores = Array();
localStorage.clear("database");
//visually cleared
document.getElementById('write').innerHTML = "storage cleared.";
}
// save the string
function saveStatusLocally() {
//grab the value of the text box
var stringToSave = inputField.value;
if ((stringToSave == null) || (stringToSave == "")) {
document.getElementById('write').innerHTML = "nothing to store.";
} else {
//push that value to the array
stores.push(stringToSave);
//clear the input field for visual
inputField.value = "";
//print that value into the local storage named database and joing by a non-breaking space
window.localStorage.setItem("database", stores.join(" "));
//confirm write
document.getElementById('write').innerHTML = "data stored.";
//clear message after 1s
setTimeout(function() {
document.getElementById('write').innerHTML = "";
}, 1000);
}
}
// read the string
function readStatus() {
//print the value of the local storage "database" key
if (window.localStorage.getItem("database") == null) {
document.getElementById('write').innerHTML = "nothing stored.";
} else {
document.getElementById('write').innerHTML = window.localStorage.getItem("database");
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.