2 Replies Latest reply: May 12, 2012 12:43 AM by BKBK RSS

    Use JavaScript to submit CFWindow form.

    jeffw2002

      Hi all,

       

      The code below is an illustration of what I want to do.  The actual form and JavaScript validation is more complex.  I am using a CFWindow that contains the form.  When a form button is selected I want to run a JavaScript form validation routine then submit.  The issue is that the browser loads the form's action page and just sits there.  What I want is the form to be submitted, the CFWindow to close like normal.  The question boils down to:  how to submit a CFWindow form using JavaScript.

       

      Thanks,

      Jeff

       

      <html>
      <head>
      <title></title>

      <script>
      function checkForm() {
      var theField = document.getElementById('Name');
      if (theField.value.length < 3){
        alert("Longer name please.")
      } else {
        document.getElementById('myForm').submit();
        //ColdFusion.Window.hide('CFWindow2');
      }
      }
      </script>

      <body>

      <cfwindow center="true" closable="true" draggable="true" modal="true" resizable="false" initshow="false"  bodyStyle="position: absolute; left; 5px;font-size:1.1em;" height="130" name="CFWindow2" title="More Information" width="300">
      <div id="myDiv2">
         <cfform id="myForm" action="processForm.cfm" method="POST" enablecab="Yes" enctype="multipart/form-data" preservedata="Yes" onSubmit="ColdFusion.Window.hide('CFWindow2')">
           Name: <cfinput type="Text" id="Name" name="Name" message="Please enter your name" required="Yes" size="27" tabindex="1" value="j"><br>
           <cfinput type="button" name="Submit" value="Submit" required="No" onClick="checkForm()">
         </cfform>
      </div>
      </cfwindow>

      <a href="javascript:ColdFusion.Window.show('CFWindow2');" onClick="document.getElementById('myDiv2').style.display='block';">CFWindow</a></p>

      </body>
      </html>

        • 1. Re: Use JavaScript to submit CFWindow form.
          jeffw2002 Community Member

          I transcended this issue by playing with field validation.  But it is still a good question should anyone have an answer to it. thx - jf

          • 2. Re: Use JavaScript to submit CFWindow form.
            BKBK MVP

            jeffw2002 wrote:

             

            Hi all,

             

            The issue is that the browser loads the form's action page and just sits there.  What I want is the form to be submitted, the CFWindow to close like normal.  The question boils down to:  how to submit a CFWindow form using JavaScript.

            I think your code behaves as expected. When I ran it, the form was submitted to the action page, which remained open, and, simultaneously, cfwindow2 was closed. That is in fact what the code is supposed to do. Did I miss something?