• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Use JavaScript to submit CFWindow form.

Explorer ,
May 10, 2012 May 10, 2012

Copy link to clipboard

Copied

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>

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2012 May 10, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2012 May 12, 2012

Copy link to clipboard

Copied

LATEST

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation