• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Passing js Variable to CF

New Here ,
Apr 02, 2009 Apr 02, 2009

Copy link to clipboard

Copied

I need to be able to pass a data variable from javascript to Cold Fusion. Is there a way to do that? Something like the ToScript in Coldfusion that allows to pass a CF variable to javascript.

Or, is there a way to write data values to a database using javascript directly? I have a set of data, that is being collected and passed via javascript. So, my thought is to pass those data values from js to Coldfusion to write them back to the database. But, let me know if there is a better way to do that.

Thanks,
Ros
TOPICS
Advanced techniques

Views

4.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Apr 16, 2009 Apr 16, 2009

Prior to CF8 you would be using CFAjax or AjaxCFC or rolling your own.

http://www.indiankey.com/cfAjax/

http://www.robgonda.com/blog/projects/ajaxcfc/

Your on your own for rolling your own.

Votes

Translate

Translate
LEGEND ,
Apr 02, 2009 Apr 02, 2009

Copy link to clipboard

Copied

javascript = client-side
cf = server-side

these are 2 parallel worlds only connected by http request/response
path... unless you stay on that path, you will never reach the other
world...


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2009 Apr 02, 2009

Copy link to clipboard

Copied

To pass ColdFusion data to JavaScript is no different then passing
ColdFusion data to HTML.

<cfset myCFvar = "Say goodnight Gracie.">
<cfoutput>
<script type="text/javascript>
var myJSvar = #myCFvar#;

alert(myJSvar);
</script>
</cfoutput>

The <cfwddx...> tag with its' CFML2JS option makes it easier to convert
complex data structures from CF to JS forms.

To pass JavaScript data to ColdFusion you have to submit it in a
request. You can submit it as a get request in the URL, as a post
request with form controls or with an Asynchronous JavaScript request
with XMLHttpRequest commonly called 'AJAX'.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2009 Apr 03, 2009

Copy link to clipboard

Copied


Thanks Ian,

Could you please give an example of the Asynchronous JavaScript request
with XMLHttpRequest commonly called 'AJAX'. This sounds like what I would need to do to pass the data values back to Cold fusions and then write them to the database.

Ros

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 03, 2009 Apr 03, 2009

Copy link to clipboard

Copied

Your best first port of call would be to read up on <cfajaxproxy>, because CF does most of this for you automatically.

http://livedocs.adobe.com/coldfusion/8/Tags_a-b_3.html

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2009 Apr 03, 2009

Copy link to clipboard

Copied


Great.. Thanks, Adam. I will check it out. -Ros

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 16, 2009 Apr 16, 2009

Copy link to clipboard

Copied

cfajaxproxy is great.. But it is only available on CF8.. We are running CF 7. So, how would you do it in that case?

thanks,

Ros

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 16, 2009 Apr 16, 2009

Copy link to clipboard

Copied

Prior to CF8 you would be using CFAjax or AjaxCFC or rolling your own.

http://www.indiankey.com/cfAjax/

http://www.robgonda.com/blog/projects/ajaxcfc/

Your on your own for rolling your own.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2009 Apr 18, 2009

Copy link to clipboard

Copied

Hi Ian,

One more question for you regarding CFAjax.. Can 2 parameters be passed to the DWREngine._execute?

All the examples that I have found only have one parameter. I figure the back up option would be to concat the variables into one string to pass them to the engine and separate them in the CFfunction, but I did not want to go down that path if there is a better way.

Thanks,

Ros

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2009 Apr 19, 2009

Copy link to clipboard

Copied

LATEST

OK, it all works great! 🙂

For those that may be looking for this answer, multiple parameters can be passed to the DWREngine._execute command by a comma separator.

DWREngine._execute(_cfscriptLocation, null, doQuery, Par1, Par2, Par3,...,doQueryResult);

Where Par1, Par2, Par3 are the parameteres being passed to the doQuery cffunction.

Thanks for everyone's help.

Ros

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2009 Apr 02, 2009

Copy link to clipboard

Copied

quote:

Originally posted by: Rouset
I have a set of data, that is being collected and passed via javascript. So, my thought is to pass those data values from js to Coldfusion to write them back to the database. But, let me know if there is a better way to do that.

Thanks,
Ros

Care to elaborte on that first sentence with particular emphasis on the word "passed".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation