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

Coldfusion and javascript

Participant ,
May 22, 2008 May 22, 2008
Can I create a javascript variable from a cf query?

I want this to be: var point = new GLatLng(43.92213170963767, -86.37434005737304);

var point = new GLatLng(#cf1#,#cf2#);
1.1K
Translate
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

LEGEND , May 22, 2008 May 22, 2008
idesdema wrote:
> Can I create a javascript variable from a cf query?
>
> I want this to be: var point = new GLatLng(43.92213170963767, -86.37434005737304);
>
> var point = new GLatLng(#cf1#,#cf2#);
>


Yes, ColdFusion is just as good at dynamically producing JavaScript to
send to a client as it is HTML, XML, CSV or about any other text format
you care to list.

<cfoutput>
<script...>
var point = new GLatLng(#cf1#,#cf2#);
</script>
</cfoutput>

I have actually done exactly what it looks li...
Translate
LEGEND ,
May 22, 2008 May 22, 2008
idesdema wrote:
> Can I create a javascript variable from a cf query?
>
> I want this to be: var point = new GLatLng(43.92213170963767, -86.37434005737304);
>
> var point = new GLatLng(#cf1#,#cf2#);
>


Yes, ColdFusion is just as good at dynamically producing JavaScript to
send to a client as it is HTML, XML, CSV or about any other text format
you care to list.

<cfoutput>
<script...>
var point = new GLatLng(#cf1#,#cf2#);
</script>
</cfoutput>

I have actually done exactly what it looks like you are doing in the past.

Translate
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
Participant ,
May 22, 2008 May 22, 2008
Ok seems easy enough. I'll give it a shot and let you know. What did you work on? I'm doing a google maps project and am clearly a hack... I think its so cool so far though.
Translate
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 ,
May 22, 2008 May 22, 2008
idesdema wrote:
> Ok seems easy enough. I'll give it a shot and let you know. What did you work on? I'm doing a google maps project and am clearly a hack... I think its so cool so far though.

It was just a prototype concept where we could show all the blood draw
locations for the local blood bank on a google map, complete with custom
blood drop 'pins'. It was never implemented.

Translate
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 ,
May 22, 2008 May 22, 2008
The general question was producing js variables from cf queries. The closest I've come was creating js arrays from a column in a cf query. Later versions of cf have a toScript function that makes this easier.
Translate
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
Participant ,
May 22, 2008 May 22, 2008
I haven't tried the first reply yet but Dan... will it not work?
Translate
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 ,
May 23, 2008 May 23, 2008
idesdema wrote:
> I haven't tried the first reply yet but Dan... will it not work?

Dan was talking about converting an entire query from ColdFusion to some
type of equivalent JavaScript variable. But your example code did not
show this.

If you are trying to get complex variables from ColdFusion to JavaScript
such as arrays, structures or queries. You will want to investigate the
<cfwddx...> tag.

<head>
...
<script type="text/javascript">

<cfwddx action="CFML2JS"
input="#myComplexVar#"
topLevelVariable="myJSvar">

</script>

But your original post did not show this.

idesdema wrote:
> var point = new GLatLng(#cf1#,#cf2#);

This shows basic simple values being output into a JS function, which my
original post demonstrated.
Translate
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
Participant ,
May 23, 2008 May 23, 2008
Yeah I'm sticking to the first approach and am testing it right now... gimme a couple minutes..
Translate
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
Participant ,
May 23, 2008 May 23, 2008
Ok so it didn't work. :(

The problem seems to be that I need to loop through a query INSIDE the script... It doesn't work.

Translate
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 ,
May 23, 2008 May 23, 2008
idesdema wrote:
> Ok so it didn't work. :(
>
> The problem seems to be that I need to loop through a query INSIDE the
> script... It doesn't work.

How does it not work? I started working with your code and I am seeing
incomplete syntax. I.E. closing brackets '}' that I do not see any
opening brackets '{' for?

If that is not the problem, can you re-use the point and markers like
that without overwriting them? I would think you would need an unique
point and marker name for each iteration of the loop?
'point#currentRow#' and 'marker#currentRow#' perhaps?
Translate
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
Participant ,
May 23, 2008 May 23, 2008
I stripped out much of the code... the javascript works on a static page so I know its ok. However, you don't need to change the names of variables. I think the problem is trying to output cf code within a javascript query.
Translate
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
Participant ,
May 23, 2008 May 23, 2008
Ok finally got it. I had a bunk row of data in my table and that was causing the issue. All set now and its working just fine with the cf inside the jscript.

Nice!

Thanks for the help.
Translate
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 ,
May 23, 2008 May 23, 2008
LATEST
idesdema wrote:
> I stripped out much of the code... the javascript works on a static page so I
> know its ok. However, you don't need to change the names of variables. I
> think the problem is trying to output cf code within a javascript query.
>

What JavaScript works in a static page? What does it look like with the
CFML added? There is no connection between cf code and a JavaScript
'query'. CFML runs on the server and has no knowledge of JavaScript .
JavaScript runs on the client and has no knowledge CFML.

All you are doing is dynamically generating JavaScript with CFML and if
this is done properly it works just fine.

Translate
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