How do you execute javascript within a cfdiv ?

Posted on 2009-04-27
Last Modified: 2013-12-20
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

Question by:LeadCo
    LVL 27

    Accepted Solution

    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)


    Author Comment

    How do i turn this into a function to be called?
    <script language="JavaScript">
    LVL 27

    Assisted Solution

    like this:

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

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


    Author Closing Comment


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
    Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
    The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following:…
    The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Open Page or Post…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now