Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to access javascript variable with CFC?

Posted on 2010-09-20
3
Medium Priority
?
274 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 1000 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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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