My objective is to store data submitted via a certain named form with one function and retrieve the data with another function. The form contains several input tags and two select tags. This is the JS code:
function storage() { if (typeof(Storage) != "undefined") { var elements = document.getElementsByTagName('input'); for (var input in elements) { input.value = localStorage.getItem(input.name); } var elements = document.getElementsByTagName('select') for (var select in elements) { select.value = localStorage[select.name]; } } alert("Success?"); } function onSubmit() { inputs = document.forms["forsendur"].getElementsByTagName("input"); selects = document.forms["forsendur"].getElementsByTagName("select"); for (var i=0; i<inputs.length; i++) { localStorage.setItem(inputs[i].name, inputs[i].value); } alert("Success?"); } This is the separate input tag that calls the storage() function:
<input type="button" class="button2" value="Last session" onClick="storage();"> This is the (partially omitted) form:
<form action="cool_url" name="forsendur" method="post"> <lots of input and select tags> <input class="button2" type="submit" value="Reikna" onClick="onSubmit();"/> </form> However, nothing happens (I can confirm that the data is being sent correctly through the form). I have included two alert() calls, which are triggered, so the functions are called and are executed.
for inloop on the html collection, use a plainforloop instead, like your do in youronSubmit().