Submit form and save values to sessionStorage

user1323294 picture user1323294 · May 2, 2012 · Viewed 8.2k times · Source

How can I save values from form to sessionStorage when the form is submitted?

Something like this?

        <form id="myForm" method="get" action="lista.html" rel="external" data-ajax="false" >

        <label for="autonumero"> Anna autonumero </label>
        <input type='tel' name="autonumero" data-corners="false"/>


        <input type="submit" onclick="saveData()" value="OK" data-theme="a" data-corners="false" />



        <script> function savedata()
{ var input = document.getElementById("autonumero");
sessionStorage.setItem("autonumero", input.value); 
</script> 






        </form>

The form needs to be submitted also so just saving the values isn't enough

Answer

Sudhir Bastakoti picture Sudhir Bastakoti · May 2, 2012

Try:

<input type="submit" onclick="return saveData();" value="OK" data-theme="a" data-corners="false" />
<script type="text/javascript"> 
function savedata() { 
  var input = document.getElementById("autonumero");
  sessionStorage.setItem("autonumero", input.value);
  return true;
} 
</script>