Solved

How to access javascript variable with CFC?

Posted on 2010-09-20
3
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

691 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