We help IT Professionals succeed at work.

Javascript loop input element, keeping values after back button

Andrew Maurer
on
744 Views
Last Modified: 2012-06-22
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>
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.