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

cfoutput in javascript

New Here ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

543

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

Deleted User
Aug 10, 2006 Aug 10, 2006
The text in your alert must be double-quoted:

Votes

Translate

Translate
New Here ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

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

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
Guest
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

The text in your alert must be double-quoted:

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 ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

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

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 ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

LATEST
Dan,

Thanks for the info about the JSStringFormat, I did not know about that function and I'm sure I will use it.
I have not written any cf since version 5...and am finding that I need to beef-up on the new version...

Thanks again,
Shawn Cowman

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 ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

Posted twice....

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 ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

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>
>

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 ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

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

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