title: Save and load input values using local storage?
body: <p>I'm trying to store via local storage all form field values (under the input id) like so <code>localStorage.setItem("input id", fieldvalue);</code> when a user clicks the "save" button. the reason being is so at a later date the user has the option of reloading the form field values instead of retyping everything the problem is the input id and name fields are not known because they are generated depending on what the user selects in the previous page (what template they choose).</p>
  
  <p>Demo (let's say this was generated):</p>
  
  <pre><code>&lt;input type="text" id="meta_title" name="seo_meta_title"&gt; 
  &lt;input type="text" id="meta_description" name="seo_meta_description"&gt; 
  &lt;input type="text" id="header" name="header"&gt; 
  
  &lt;!-- Submit form--&gt;
    &lt;input type="submit" value="Create"&gt;
  
  &lt;!-- buttons--&gt;
    &lt;button onclick="save()"&gt;save&lt;/button&gt;
    &lt;button onclick="load()"&gt;load&lt;/button&gt;
  </code></pre>
  
  <p>because I don't know the input ids, I can't just write:</p>
  
  <pre><code>function save() {
    if (typeof(Storage) != "undefined") {
  
      //some_code_to_insert_value = x, y, z 
  
      localStorage.setItem("meta_title", x);
      localStorage.setItem("meta_description", y);
      localStorage.setItem("header", z);
     }
  }
  </code></pre>
  
  <p>And same goes for the load function</p>
  
  <pre><code>// LOAD
  function load() {
  if (typeof(Storage) != "undefined") {
     // Adds data back into form fields 
  
     document.getElementById("meta_title").value = localStorage.getItem("meta_title");
     document.getElementById("meta_description").value = localStorage.getItem("meta_description");
     document.getElementById("header").value = localStorage.getItem("header");
  
      }
  }
  </code></pre>
  
  <p>I'm very new to JavaScript as I'm sure you can tell any help, code or links would be much appreciated and a working js fiddle would be beyond amazing (as long as it doesn't rely on pre-knowing the input id etc..) I have spent a few hours trying to do this and wasted even more time trying to generate the JS needed with PHP in till I was told this was a terrible way to do it.</p>