Submit Your Site For Free!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

DevWebProDK
FlashNewz
DevWebPro










Running JavaScript Functions From Within ColdFusion 8 Containers

By Raymond Camden
Expert Author
Article Date: 2008-01-02

This morning a discussion came up on cf-talk about how to run JavaScript functions from within ColdFusion 8 containers. (What do I mean by 'container'? I mean any of the new Ajax UI elements like the Pod or Window.)

The person asking the question was trying to use ColdFusion.navigate. I can see how you could possibly think this would work. One way to run JavaScript functions is with links, as in:

<a href="javascript:test()">Run test()</a>

But that isn't what you want to use here. Instead - the solution is much simpler. When you use containers, they execute in the context of the page itself. That means you can run any code using the same type of code I used above. Consider this full example:

<script>
function parentSayHi() {
   alert("Hi, I'm the parent, and I'm saying hi.");
}
</script>

<p>
<a href="javascript:parentSayHi()">Test parentSayHi</a>
</p>

<cfpod title="My Pods Rock the Casbah">
Another <a href="javascript:parentSayHi()">test</a>.
</cfpod>

<cfpod title="The iPod Pod" source="test3.cfm" />


In this example I've created a simple JavaScript function, parentSayHi. I then show an example of what I describe above - a link that runs the function.

The next block of code shows an inline cfpod tag. Notice again though the simple link to run the function.

Lastly I have a pod that uses an external source. The code for this file is:

Yet another <a href="javascript:parentSayHi()">test</a>.

As you can see - it too is a simple link. When run, all three of these links have no problems running the JavaScript function.

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.



DevWebProDK is an iEntry, Inc. ® publication - All Rights Reserved Privacy Policy and Legal