7 Replies Latest reply on Aug 10, 2006 2:45 PM by GO_BIGRED

    cfoutput in javascript

    GO_BIGRED
      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
        • 1. Re: cfoutput in javascript
          TWPMDan
          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

          • 2. cfoutput in javascript
            TWPMDan Level 1
            Posted twice....
            • 3. Re: cfoutput in javascript
              jdeline Level 1
              The text in your alert must be double-quoted:
              • 4. Re: cfoutput in javascript
                Level 7
                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>
                >
                • 5. Re: cfoutput in javascript
                  GO_BIGRED Level 1
                  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

                  • 6. Re: cfoutput in javascript
                    GO_BIGRED Level 1
                    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
                    • 7. Re: cfoutput in javascript
                      GO_BIGRED Level 1
                      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