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
very nice, can't wait to try
# Posted By pakbehl | 5/31/09 9:28 PM

Calendar

Sun Mon Tue Wed Thu Fri Sat
   1234
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 javascript misc model-glue off topic personal project learn slidesix sql

Recent Comments

Adding Auto Generated Code Downloads to BlogCFC
ada5fsa said: http://www.ibiblio.org/st... http://www.ncaonline.org/...... [More]

Chinese Birth Calendar Accuracy Test
mama to be said: ok so i will be 2 months shy of 18 when i have my baby. this calendar does not technically work for ... [More]

Fixing 'User Profile Service Failed The Logon' on Vista
Mike said: That fix worked although all i did was remove .bak and reset state to 0. User was able to log in to... [More]

Chinese Birth Calendar Accuracy Test
Melissa said: Wrong for my daughter, which it predicted to be a boy... we'll see for #2. Predicts a girl (maybe, f... [More]

Adding Auto Generated Code Downloads to BlogCFC
fweerw said: http://www.ibiblio.org/st... http://www.cambodia.ait.a...... [More]

RSS


adobe community experts

coldfusionbloggers

FullAsAGoog MXNA

Consumed By Feed-Squirrel.com