Skip to main content
Participant
August 10, 2006
Answered

cfoutput in javascript

  • August 10, 2006
  • 3 replies
  • 654 views
Hello,

I can't seem to figure out why the below code does not work. I'm just trying to create an array from a cfquery. The code does not give any errors. but the alerts are not working. If I view the source of the browser page I can see the array has the right information in it from the db. Why aren't the alerts popping up?

Thanks.
Shawn Cowman
This topic has been closed for replies.
Correct answer
The text in your alert must be double-quoted:

3 replies

Inspiring
August 10, 2006
I don't think the alerts will ever do what you want them to do.
Remember this is a deference between the server and the client. CFML is
processed on the server completely, then sent to the client. JavaScript
is processed on the client after the request has been sent from the server.

If you did work out the syntax to build the alerts you are just going to
get this in the source code of the browser.

...
alert(...);
...
alert(...);
...
alert(...);
...
ect.

Then when the ColorInfo function is called in the browser, all the
alerts are going to fire off one after the other.

What is it you are trying to accomplish and we maybe able to help figure
this out.

GO_BIGRED wrote:
> Hello,
>
> I can't seem to figure out why the below code does not work. I'm just trying
> to create an array from a cfquery. The code does not give any errors. but the
> alerts are not working. If I view the source of the browser page I can see the
> array has the right information in it from the db. Why aren't the alerts
> popping up?
>
> Thanks.
> Shawn Cowman
>
> --QUERY SECTION--
> <cfquery name="ShirtColors" dataSource = "#Application.DB#">
> Select Color_ID, Name_V, HEX_V, ImageName
> From Qry_Gildan2000_Display_Yes
> </cfquery>
>
>
> --JAVASCRIPT SECTION--
> <script type="text/javascript" language="JavaScript">
>
> function ColorInfo(Color_ID, Name_V, HEX_V, ImageName) {
> this.Color_ID = Color_ID
> this.Name_V = Name_V
> this.HEX_V = HEX_V
> this.ImageName = ImageName
> }
>
> var G2000_C = new Array()
> G2000_C[0] = new ColorInfo("Color_ID", "Name_V", "HEX_V", "ImageName")
> <cfoutput query="ShirtColors">
> G2000_C[#CurrentRow#] = new ColorInfo(#Color_ID#, '#Name_V#', '#HEX_V#',
> '#ImageName#');
> alert (Finished Row '#CurrentRow#');
> </cfoutput>
>
> alert (G2000_C[1].Color_ID+" - "+G2000_C[1].Name_V+" - "+G2000_C[1].HEX_V+" -
> "+G2000_C[1].ImageName);
> </script>
>
GO_BIGREDAuthor
Participant
August 10, 2006
Ian,

The alerts are only for testing...I will remove them when I'm finished with this part of the application.
The Client/Server thing is the reason I'm making an array in js. So that I can have information change on my page without reloading the browser. Once I make the array in js I no longer need the cf recordset or cf...This is static information that does not go back to the server once loaded...However if I understand it correctly once I have the Recordset as a named query in cf I'm not hitting the database any longer anyway, so I don't think that it is a Client/Server problem. It was the double-quotes for the alert message that caused my problem. Now am I correct in thinking of this js array as a Recordset that I can access with other js functions by having links that pass the Color_ID to the function and then reading that row in the array?

Thanks,
Shawn Cowman

Participating Frequently
August 10, 2006
Posted twice....
Participating Frequently
August 10, 2006
Hi Shawn,

I would suggest 2 things:

Put the color_id in single quotes

Use JSStringFormat() around your cf vars incase some of the data is breaking the JS with unescaped chars

Correct answer
August 10, 2006
The text in your alert must be double-quoted:
GO_BIGREDAuthor
Participant
August 10, 2006
jdeline,

Thanks, That was it...I swear I double checked the syntax last night...After my 3rd pot of coffee I quess I was seeing what ever I needed to....

Thanks again,
Shawn Cowman