So I'm trying to build a form for submitting input data and I want the values for each individual element to be stored as a Javascript variable so I can use SessionStorage to access them from another page (I don't want to send the data to a server since I can't pay for one and I don't intend on sending this to multiple users anyway). Problem is that no matter how I try to do it, the values are coming up as null. Here's my code (I changed the variable names because they're sensitive data, but I've checked the actual names and they're not reserved):
<form id="form_updates" method="post">
Input 1: <br>
<input type="text" name="input1" id="input1"><br>
Input 2: <br>
<input type="text" name="input2" id="input2"><br>
Input 3: <br>
<input type="text" name="input3" id="input3"><br>
<button onclick storeValues()>Update Form</button>
</form>
<script>
function storeValues(){
sessionStorage.setItem("ses1", "<?php echo $_POST['input1'] ?>");
sessionStorage.setItem("ses2", form_updates.elements[1].value);
sessionStorage.setItem("ses3", document.getElementById("input3").value);
}
So the code is a mess right now, I'm aware of that, I've been testing multiple solutions and none of them seem to work (once I figure out something that works I'll apply that consistently throughout the code). I've tried using an event listener on the button, and I've tried reading the form. I've tried all three of those methods to store the values inside and outside of storeValues(). Every time, it always evaluates to null. I've been researching this issue for days and I can't seem to figure this out. Please help!