Link to home
Start Free TrialLog in
Avatar of Andrew Maurer
Andrew MaurerFlag for United States of America

asked on

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>
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial