I am trying to create a program which takes an input number, stores it into localStorage on a button click and then loads it when a separate button is clicked. Essentially a save/load feature. The problem is that I need to save an ID from another function.
I've already tried to call the other function within my save/load functions and I've tried various other ideas, but I'm extremely new to using localStorage (or any kind of storage).
This is the function with the ID I want to save (qty1) followed by my save/load functions (which don't seem to work).
function modify_qty(val) {
var qty = document.getElementById('qty1').value;
var new_qty = parseInt(qty,10) + val;
var max = document.getElementById('max1').value;
if (new_qty < 0) {
new_qty = 0;
}
if (isNaN(new_qty)) {
new_qty = 0;
}
if (new_qty > max) {
new_qty = max;
}
document.getElementById('qty1').value = new_qty;
return new_qty;
}
function save() {
return function(modify_qty) {
localStorage.setItem('qty', qty1);
}
}
function load() {
return function(modify_qty) {
var qty1 = localStorage.getItem('qty');
document.getElementById('qty1').value = qty1;
return qty1;
}
}
I need the save function to save the id "qty1" into localstorage so that the load function can later pull it back and replace the current value with the saved value. Right now, I don't think either of the save/load functions are working, as I save the value, reload, try to load, and nothing happens. For my testing purposes, I have the max variable disabled, so that's not it.