I am currently using local storage to transfer two form inputs from a form on page A to a form on page B. The process is working smoothly, but I have encountered an issue. When I navigate directly to page B or visit it without inputting any data on page A, the form fields on page B appear blank. Is there a way to ensure that local storage only passes variables if they exist?
Any assistance would be greatly appreciated!
Below is the code I have implemented so far:
function pageSel() {
var parseAmount = document.getElementById("stepperAmount").value;
var parseMonth = document.getElementById("stepperMonth").value;
localStorage.setItem("amountKey", parseAmount);
localStorage.setItem("monthKey", parseMonth);
}
Page B.
function pageSel2() {
var parseAmount2 = localStorage.getItem("amountKey");
var parseMonth2 = localStorage.getItem("monthKey");
document.getElementById("demo1").value = parseAmount2;
document.getElementById("demo2").value = parseMonth2;
}
function roundAmount() {
var x=document.getElementById("demo1");
x.value=Math.round(x.value/250)*250;
}
function roundMonth() {
var x=document.getElementById("demo2");
x.value=Math.round(x.value/12)*12;
}
pageSel2();