Solved

How to access javascript variable with CFC?

Posted on 2010-09-20
3
268 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CFC Lookup - When Not Found 5 75
ColdFusion Need assistance updating my legacy zip function 13 44
REGEX HELP 11 48
ColdFusion not showing binary json data in request 4 31
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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