Ioannis,

I'll phrase my reply somewhat differently (though I think most 
respondents did mention this) -- It's not possible to do it exactly the 
way you suggested. AJAX *does* make this possible. Using AJAX you can 
make a call to the server from the client without the browser refreshing.

I'll not get into the details of how this works, but will instead 
suggest a couple of my favorite libraries that make this code easier: 
ajaxCFC, and jQuery. ajaxCFC isn't really a library, but rather a 
wrapper or extension that was built around a javascript library called 
DWR. Very soon it will work with jQuery too, and that's exciting.

Check out ajaxCFC <http://ajaxcfc.riaforge.org/> over on RIAForge 
<http://riaforge.org>.

jQuery is a full-blown javaScript library that is very lightweight and 
powerful. Check out these links for jQuery:

jQuery Ajax/Javascript library <http://jquery.com>
jQuery API <http://joern.jquery.com/api-draft/cat.xml> (there's a couple 
of different places this is kept, but this one's my favorite)
jQuery Documentation <http://jquery.com/docs/>
jQuery Tutorials <http://jquery.com/tutorials/>
jQuery Plugins/Widgets <http://jquery.com/plugins/>
jQuery Demos <http://jquery.com/demos/>
Learning jQuery Web Resource Center <http://www.learningjquery.com/>
Visual jQuery <http://www.visualjquery.com> (another API link. Only 
difference is how it's displayed on screen)
Visual jQuery Magazine <http://www.visualjquery.com/magazine/>

Just to give you an example of what the code for ajaxCFC might look 
like, here's a function that I used once in an app.:

function GetTheNextID(){
    var UserName = "#CGI_AUTH_USER#";
    var IPAddress = "#CGI_REMOTE_ADDR#";
    DWREngine._execute("FlexOrdering.cfc", null, "FetchNextID", 
{"UserName":UserName, "IPAddress":IPAddress}, DisplayNextID);
}

A small sample of a jQuery ajax call:

function ClearCellData(obj){
    $.ajax({
        type: "POST",
        url: "ClearFlexCalendarData.cfm",
        datatype: "html",
        data: "date=" + obj.dateValue,
        success: function() {
            // re-calculate the start and end dates
            ReCalculateStartEndDates();
        },
        error: function(){
            alert("Error: check the CF logs");
        }
    });
}

You'll notice that in the jQuery example I'm not directly calling a CFC. 
It's not impossible, but much, MUCH trickier to deal with. So much so, 
that it's not really worth it. However, that's what's so exciting about 
the mix of ajaxCFC and jQuery. It's in alpha release right now (I'll be 
testing it tonight), and will be out for beta next week. This means 
we'll be able to make ajax calls directly to our CFCs from jQuery. Very 
exciting. :o)

I know this has rambled a bit, and I don't know your knowledge level, 
but just check out some of those links I gave you. Both ajaxCFC and 
jQuery have active, friendly and helpful communities.

I hope this at least shows you about about what's possible, and gives 
you an avenue of research to further your knowledge on how to call a CFC 
function from within JavaScript. The only way is AJAX, and that's kinda 
the bleeding edge right now. So that's what I'd suggest you do some 
reading on.

Cheers,
Chris


Ioannis Papanikolaou wrote:http://www.visualjquery.com/magazine/
> Hello people,
>
> Do you know how can I actually call a Coldfusion funsction with a javascript 
> function.
>
> for example I am using onClick to call a cffunction inside a div. (DOM)
>
> Example:
> <!--
> <body>
> <cffunction name="MyExample" output="yes" returntype="string">
> <cfreturn "My DOM Coldfusion Example">
> </cffunction>
>
>
> <br />
>
> <a href="#"onClick='document.getElementById("contentMain").innerHTML = 
> "#MyExample()#";'>example</a></li>
>
> <div id="contentMain">
> </div>
>
> </body>
> -->
>
>
> And of cource my result after I click it would be #MyExample()# instead of 
> the text.
>
> I am sure that as a newbe I am doing a syntax mistake somewhere or something 
> is 
>
> missing but I am struggling with this 3 hours already. 
>
> Thanx in advance.
>
> Any Ideas more than welcome...!!!
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:265176
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to