Posted in ColdFusion | Posted on 12-27-2007 | 4,221 views
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:
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:
2function parentSayHi() {
3 alert("Hi, I'm the parent, and I'm saying hi.");
4}
5</script>
6
7<p>
8<a href="javascript:parentSayHi()">Test parentSayHi</a>
9</p>
10
11<cfpod title="My Pods Rock the Casbah">
12Another <a href="javascript:parentSayHi()">test</a>.
13</cfpod>
14
15<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:
As you can see - it too is a simple link. When run, all three of these links have no problems running the JavaScript function.


My main reason for trying was to use spry form validation. Have not figured this out so far either.
If I place the alert code before or after the widget code as Ray suggested in another thread, it works and alert is fired.
The spry validation, however still does not work. Even if I set it to validate on blur and change.
The same exact code works with spry HTML panel
I will keep you posted if I find anything further.