Solved

How to access javascript variable with CFC?

Posted on 2010-09-20
3
265 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
Comment Utility
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
Comment Utility
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
Comment Utility
wrap you code in a function and then put this at the bottom of the page

<cfset AjaxOnLoad("function_name_here")>
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Entering multiple email addresses 4 58
https json cfhttp post 1 80
cfgrid format issue and columns missing 4 78
multi page pdf 4 69
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

9 Experts available now in Live!

Get 1:1 Help Now