Skip navigation
jeffw2002
Currently Being Moderated

Use JavaScript to submit CFWindow form.

May 10, 2012 9:16 AM

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';">CF Window</a></p>

</body>
</html>

 
Replies
  • Currently Being Moderated
    May 12, 2012 12:43 AM   in reply to jeffw2002

    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?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points