0
Participant
,
/t5/coldfusion-discussions/coldfusion-and-javascript/td-p/410389
May 22, 2008
May 22, 2008
Copy link to clipboard
Copied
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#);
I want this to be: var point = new GLatLng(43.92213170963767, -86.37434005737304);
var point = new GLatLng(#cf1#,#cf2#);
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
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...
> 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...
LEGEND
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410390#M36933
May 22, 2008
May 22, 2008
Copy link to clipboard
Copied
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.
> 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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
idesdema
AUTHOR
Participant
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410391#M36934
May 22, 2008
May 22, 2008
Copy link to clipboard
Copied
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410392#M36935
May 22, 2008
May 22, 2008
Copy link to clipboard
Copied
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.
> 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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410393#M36936
May 22, 2008
May 22, 2008
Copy link to clipboard
Copied
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
idesdema
AUTHOR
Participant
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410394#M36937
May 22, 2008
May 22, 2008
Copy link to clipboard
Copied
I haven't tried the first reply yet but Dan... will it not
work?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410395#M36938
May 23, 2008
May 23, 2008
Copy link to clipboard
Copied
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.
> 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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
idesdema
AUTHOR
Participant
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410396#M36939
May 23, 2008
May 23, 2008
Copy link to clipboard
Copied
Yeah I'm sticking to the first approach and am testing it
right now... gimme a couple minutes..
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
idesdema
AUTHOR
Participant
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410397#M36940
May 23, 2008
May 23, 2008
Copy link to clipboard
Copied
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.
The problem seems to be that I need to loop through a query INSIDE the script... It doesn't work.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410398#M36941
May 23, 2008
May 23, 2008
Copy link to clipboard
Copied
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?
> 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?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
idesdema
AUTHOR
Participant
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410399#M36942
May 23, 2008
May 23, 2008
Copy link to clipboard
Copied
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
idesdema
AUTHOR
Participant
,
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410400#M36943
May 23, 2008
May 23, 2008
Copy link to clipboard
Copied
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.
Nice!
Thanks for the help.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/coldfusion-and-javascript/m-p/410401#M36944
May 23, 2008
May 23, 2008
Copy link to clipboard
Copied
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.
> 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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

