How do you execute javascript within a cfdiv ?

I have a page that uses cfdiv and the URL that is calld by the cfdiv is a form that the user fills out. When the user clicks to process the form their is some logic that  processing the form to check validity of data and then the info need to be posted to an external page that should open in a new window.

The issue:
page 1 opens cfdiv - form on cfdiv processes and will not open a new window even with target = "_blank".

Also I have javascript that auto submits form data for the validation page to the external page. If I could get the javascript to run the document.form.submit() it would be OK.

Howewer I am finding that javascript does not process in a cfdiv.
A solution to either would solve my problem:
Opening the form submit in a new window from the cfdiv
Figure out how to run the javascript in cfdiv to auto subit form.

<!---  example --->
index.cfm with cfdiv area
<!---  cfdiv --->
<cfdiv bindonload="false" bind="url:Apprequest.cfm?idvar=#id#&apply={Apply@click}" />
<!---  the url : Apprequest.cfm--->
<cfform action="apply.cfm"  target="_blank" method="post">
fields .......
Even with the target = "_blank" it does not open in new window.  (1 st problem)
<!---  Next (we are still on Index.cfm we have processed the form )--->
<form action="http://www.URL/post.php" method="post" target="_blank" name="Apply">
  <script language="JavaScript">
<!---  This fails to submit ---->

Open in new window

Who is Participating?
1) when you use CFFORM in CF8 ajax containers (like cfdiv or cfwindow) - the form will automatically submit to that container, without refreshing the whole page. adding a TARGET attribute to CFFORM tag does not change this default behaviour.  
using a regular FORM tag will make the form submit to the master page, replacing the page. i can't remember right now if target attribute works in this case or not, but i imagine it should...

2) to run a js function automatically on pageload inside a CF ajax container, use ajaxOnLoad() built-in function.
add this to the very end of the .cfm page loaded in your cfdiv, just before the closing </body> tag:
<cfset ajaxOnLoad('name-of-js-function-to-execute')>

(NOTE: you can't pass any arguments to the function you execute via ajaxOnLoad)

LeadCoAuthor Commented:
How do i turn this into a function to be called?
<script language="JavaScript">
like this:

<script type=="text/javascript">
var submitForm = function(){

then in the page loaded inside cfdiv you would have
<cfset ajaxOnLoad('submitForm')>

LeadCoAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.