So I have created a submission form that will calculate a final value based on what is inputed. I want to be able to display this value on a separate page when the user clicks a button.
I initially tried displaying the value on the same page upon clicking a button. This worked, but I haven't figured out how to display it on another page when clicking this button. I was trying to figure out how to use sessionStorage to make this happen, but I don't think I am using it correctly. At this point, clicking the button will send the user to the second page, but the final value doesn't show up there. I am very new to coding, so I appreciate the help!
Page 1 JS
function computeval(){
var distance1 = document.getElementById('distance1').value;
var distance2 = document.getElementById('distance2').value;
var hotel = document.getElementById('hotel').value;
var emair = (distance1 * 0.0665).toFixed(2);
var emland = emair + (distance2 * 0.1809).toFixed(0);
var totalem = emland + (hotel * 19.2).toFixed(0); totalem.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
tot=document.getElementById('totalem').innerHTML = "Total Emissions (kg) = "+totalem;
}
function handleSubmit () {
localStorage.setItem('em', tot);
}
Page 1 HTML
<form action="result.html" method="POST">
<button type="submit" class="btnop" onclick="handleSubmit()" >Submit</button>
</form>
Page 2 JS
localStorage.getItem('em');
page 2 HTML
<body>
<h1>
Result Page
</h1>