• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 729
  • Last Modified:

Javascript loop input element, keeping values after back button

I am using a form similar to this and it works great. I am trying to repleat form elements to save on network traffic, but, once submitted and then the back button is pressed on the browser, all the values are cleared unlike if I were to have a static 10 element form (all the values would match). Is it possible to make this form work with the back button filling in the entered data?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Submit form</title>
    <script>
  function genForm() {
        var html = "";
        var target = document.getElementById('formFields');

        for (var n=1; n <= 10; n++){
            html += '<input type="text" name="address' + n + '" value="" >';
            }
        target.innerHTML = html;
    }      
</script>
</head>
<cfoutput>
<body onload="genForm()">
      <form action="index.html" method="post" name="myform">
              <div id="formFields"></div>
            <input type="hidden" name="state" value="ca">
            <input type="submit" value="GO">
      </form>
</body>
</html>
0
Andrew Maurer
Asked:
Andrew Maurer
1 Solution
 
basicinstinctCommented:
You could store all of the answers in a cookie and then read them when the page loads and generate your dynamic fields accordingly.  This is the only way it could be done client side.

If I was doing this I would do it with server side code.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now