Q:

Sending HTML form inputs into Javascript function for local storage

Trying to grab form data into a javascript.  I'm not sure why this isn't working.
<!DOCTYPE html>
<html>
<body>

    <form action="site2.html" onsubmit="store()">
        Enter your name: <input type="text" name="name" />
        Enter your age: <input type="text" name="age" />
        <input type="submit" />
        </form>

<!-- <div id="result"></div> -->

<script>
    function store() {
        // Check browser support
        if (typeof(Storage) !== "undefined") {
        var s = document.getElementById("name").value;
        localStorage.setItem("lastname", s);
        }
    }
</script>

</body>
</html>

A:

It won't work in this snippet because localStorage is prevented in a sandboxed area. The code is just here for reference. You can see it working in this jsFiddle. If you submit the form and refresh/re-run the page you'll see that it even sets the input values from localStorage too. Furthermore this will work with whatever fields exist in the form. Add some more inputs to see it working. (Make sure you give them a name)
Working jsFiddle (assuming your browser supports localStorage):
https://jsfiddle.net/jcgodLt6/1/
SO Snippet (here for reference):

var form = document.getElementById("myform");
form.addEventListener("submit", store, false);

function store(e){
e.preventDefault();//prevent submission
  var inputs = form.elements;
  for (let i = 0; i < inputs.length; i++) {
    localStorage.setItem(inputs[i].name, inputs[i].value);
    console.log(inputs[i].name, inputs[i].value);
  }
}

function retrieve(){
  var inputs = form.elements;
  for (let i = 0; i < inputs.length; i++) {
    inputs[i].value = localStorage.getItem(inputs[i].name);
    console.log(inputs[i].value);
  }
}

retrieve();
  <form action="site2.html" onsubmit="store()">
        Enter your name: <input type="text" name="name" />
        Enter your age: <input type="text" name="age" />
        Fave thing: <select name="fave"><option>Bees</option><option>Jam</option></select>
        <input type="submit" value="submit" />
        </form>

