Discussion Area

ask questions, discuss topics, solve problems

This is a public Discussion Area  publicRSS

Thread

    • Evaluate('form.control') -...
      Thread posted Oct 28 by krknaveen, last edited Oct 29
      178 Views, 1 Comment
      Title:
      Evaluate('form.control') - Error
      Content:

      I am generating a textbox dynamically using JavaScript.

      The Controls donot stay when clicking on the submit button.

      The sample code is given belos viz.,

      /* ---------- CFM Code Start ---------- */


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
          <title>Sample Page</title>
          <script language="javascript" type="text/javascript">
              function fnAdd(ContainerId)
              {
                  try
                  {
                      var objParent;
                      var objControl;
                      var objCountControl;
                     
                      objCountControl = document.getElementById('CountTextBox');
                      objParent = document.getElementById(ContainerId);
                     
                      objCountControl.value = parseInt(objCountControl.value) + 1;
                     
                      objControl = document.createElement('input');
                      objControl.setAttribute('id', objCountControl.value+'_TextBox');
                      objControl.setAttribute('name',objCountControl.value+'_TextBox');
                      objControl.setAttribute('value',objCountControl.value);
                      objParent.appendChild(objControl);
                  }
                  catch(err)
                  {
                      alert("Error Occured (fnAdd): " + err.description);
                  }
              }
          </script>
      </head>
      <body>
          <form method="post">
              <cfoutput>
                  <cfif isdefined('SubmitButton')>
                  <cfdump var="#form#">
                      <cfif isdefined('form.CountTextBox') and form.CountTextBox gt 0>
                          <cfloop index="iCounter" from="1" to="#form.CountTextBox#">
                              #evaluate("form.#iCounter#_TextBox")#
                          </cfloop>
                      </cfif>
                  </cfif>
                 
                  <div id="ContainerDiv" style="width: 200px;"></div>
                  <input type="button" id="AddButton" name="AddButton" onclick="javascript:fnAdd('ContainerDiv')" value="Add" />
                  <input type="submit" id="SubmitButton" name="SubmitButton" value="Submit" />
                  <input type="hidden" id="CountTextBox" name="CountTextBox" value="0" />
              </cfoutput>
          </form>
      </body>
      </html>


      /* ---------- CFM Code End ---------- */


      Can anyone please help?

      Naveen

    Comments

    • I have corrected the JavaScript to set the name attribute of the textbox.

      It works in IE.

      Naveen