Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do you execute javascript within a cfdiv ?

Posted on 2009-04-27
4
Medium Priority
?
1,989 Views
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
OR
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 .......
Submit
 
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">
hiddenfield
hiddenfield.....
  <script language="JavaScript">
<!--
document.Apply.submit();
//--
</script>
</form
 
<!---  This fails to submit ---->

Open in new window

0
Comment
Question by:LeadCo
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
azadisaryev earned 2000 total points
ID: 24241065
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)

Azadi
0
 

Author Comment

by:LeadCo
ID: 24245156
How do i turn this into a function to be called?
<script language="JavaScript">
document.Apply.submit();
//--
</script>
0
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 2000 total points
ID: 24246941
like this:

<script type=="text/javascript">
var submitForm = function(){
  document.Apply.submit();
};
</script>

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

Azadi
0
 

Author Closing Comment

by:LeadCo
ID: 31574830
Perfect!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
Suggested Courses

578 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