CFAjaxproxy Bind Magic

I'm working on a small project with some of the ColdFusion 8 Ajax magic and on a whim decided to try using cfajaxproxy in a 'creative' manner.  Turns out it worked quite nicely. Here's my situation: In the past we would put our JavaScript calls inline on an HTML element (in an onClick event or some such) or we'd use the good old <a href="javascript:foo();"></a> method. The recent unobtrusive, cross-browser compatible trends have lead us to use our JavaScript framework to attach these events. For example in Spry we might have:

<script>
foo = function(){
alert('you clicked me!');
}
//attach the event to the fooDiv
Spry.Utils.addLoadListener(function(){
   Spry.Utils.addEventListener("fooDiv", "click", foo, false);
});
</script>

<div id="fooDiv" style="cursor: pointer;">click me</div>

So part of my project is to highlight the beauty, power and simplicity of the ColdFusion 8 Ajax functionality. With that in mind I thought of the cfajaxproxy tag which can be used to bind form elements. I decided to try using it with a div instead, and it turns out it worked. There is one minor catch - cfajaxproxy requires a simple value to be passed. Simply passing the id of the div won't work because CF evaluates that id to the HTML element - which is not a simple value. I got around that by passing the innerHTML value of the div like so:

<cfajaxproxy bind="javascript:foo({fooDiv.innerHTML@click})" />
<script>
foo = function(){
alert('you clicked me!');
}
</script>
<div id="fooDiv" style="cursor: pointer;">click me</div>



Comments
This doesn't seem to attach the click event to the actual div. I played around with it a bit and simply putting a line break between "me" and the closing div breaks the binding.

I like the idea, but maybe there is a better way to pass a simple value than the innerHTML.
# Posted By Matt Williams | 1/8/08 2:07 PM
A quick try on passing the id seems to work:
bind="javascript:foo({fooDiv.id@click})"
# Posted By Matt Williams | 1/8/08 2:10 PM
Sweet! Thanks for posting the update!
# Posted By todd sharp | 1/8/08 3:11 PM
Im going to try this with ThickBox from a cfdiv...
# Posted By Chris Smith | 1/10/08 5:49 PM
Nice, I gonna try
# Posted By BMSPACK | 1/15/08 3:24 AM

Calendar

Sun Mon Tue Wed Thu Fri Sat
    123
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Subscribe

Enter your email address to subscribe to this blog.

Tags

actionscript ajax blogging cfsnippets coldfusion flash forms flex funny stuff misc model-glue off topic personal project learn slidesix sql

Recent Comments

Managing Sessions In CF Ajax Applications
jlomoglio said: I tried adding this code into my application and when I run it I get the following error: The THENA... [More]

ColdFusion/Sharepoint Integration - Part 1 - Authenticating
share point said: Hi Great Article, I'm new to Sharepoint and this is a great reference to have for our implementation... [More]

TechCrunch/CrunchGear Meetup - The Aftermath
Sam Farmer said: Very cool. [More]

Eclipse - You're Killing Me
Jane Carter said: Eclipse is a nightmare. I have been trying to use CFEclipse - I had to hunt for hours for a hack ju... [More]

Using Flash Forms Inside Of CF 8 Ajax Containers
Howard Ross said: @Gavy I am currently using a work around similar to one you suggest. I use a png type cfchart in a... [More]

RSS


coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com