Solved

How to access javascript variable with CFC?

Posted on 2010-09-20
3
266 Views
Last Modified: 2012-05-10
Experts,
I would like to understand the best approach to accessing a javascript function from Coldfusion. Can someone please, in the simplest terms possible, please give an example of a way to do the following. Coldfusion 8.

<script>
   var hasThePlugin = isInstalled();
</script>

<cfset CFhasThePlugin = hasThePlugin>

Open in new window


I have no access to the "isInstalled" js function.

I feel this is a simple implementation of the cfajaxproxy tag but I'm just not getting it.

Thanks!
<script>

   var hasThePlugin = isInstalled();

</script>



<cfset CFhasThePlugin = hasThePlugin>

Open in new window

0
Comment
Question by:MPMueller
3 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 33720504
It depends what you want to achieve.
What you will never get is the JavaScript values arrive on ColdFusion side before the page was sent to browser.
And that is the problem.
All ColdFusion page source is executed first on server side and sent then to browser as Text page.
Then is that Text page executed as HTML. JavaScript sections on that HTML page can do a second ColdFusion call to another CF page or CFC function to post values or get values. But those values cannot be applied to the initial ColdFusion page because that page finished execution before it was sent to the browser.

You see?


0
 

Author Comment

by:MPMueller
ID: 33721335
Yes, and the more research I've done the more I understand, thanks for the reply.

I have successfully managed to use cfajaxproxy to update the value of a form element based on the reply to that function call, and that will work for me.

Apologies if this is off topic, but is it possible for my bind in the proxy to be fired when the page loads, as opposed to relying on a users action?

Something like:



<cfajaxproxy bind="javascript:isInstalled({vLoginName@PAGELOAD})" onsuccess="callBackHandler">

Open in new window

0
 
LVL 6

Assisted Solution

by:reiters
reiters earned 250 total points
ID: 33731054
wrap you code in a function and then put this at the bottom of the page

<cfset AjaxOnLoad("function_name_here")>
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now