7 Replies Latest reply on Jul 8, 2007 3:12 AM by BKBK

    Calling custom CF tag from javascript

    ironyx Level 1
      Could someone please help me by posting some psuedo code to call a custome cf tag from javascript? I am feeling pretty dumb but can't figure it out...

      Thanks bunches!
      Va.
        • 1. Re: Calling custom CF tag from javascript
          Dan Bracuk Level 5
          Javascript runs on the client. Cold fusion runs on the server. There are ways around this, but it depends on how you are starting the javascript and what the custom tag does.

          • 2. Re: Calling custom CF tag from javascript
            ironyx Level 1
            Press button, call tag to export to excel... so client, server shouldn't be an issue... :-)

            thanks,
            Va.
            • 3. Re: Calling custom CF tag from javascript
              Dan Bracuk Level 5
              Have the button submit a form to another cf page that calls the custom tag. If you don't want to actually leave the page you are on, put the target page into a little bitty iframe.
              • 4. Re: Calling custom CF tag from javascript
                Level 7
                > Press button, call tag

                Where is the button? Where is the tag?

                The button is activated by the user of the client browser, and any your
                JavaScript event handler on that is being run by the client browser.

                The tag is residing on the CF applicationserver, and requires to be
                executed *by* that server.

                There is never any connection between the client browser and the CF server.
                There is the network, a web server, and a webserver/CF gateway lying
                between the client browser and the CF application server; and the two NEVER
                directly interact.


                > so client, server shouldn't be an issue

                I think you need to stop and think about where all the components in this
                process reside, and what executes them.

                And then you will see that any activity on the browse side of things needs
                to call back to the server side of things to get CF to run its custom tag
                (or any other CF code, for that matter).

                --
                Adam
                • 5. Re: Calling custom CF tag from javascript
                  ironyx Level 1
                  Sorry, I wasn't trying to sound obnoxious... typed before I thought!

                  Actually yeah, guess I wasn't thinking about it... we'll do a javascript function to feed back into the cf page. And I actually think we want to leave the page.. into a completely new excel file. I am kind of a third party so I only got asked and couldn't think it through, but that helped... :-) I had never done it with a custom tag, just fed the page back into itself with the cfcontent...

                  Thanks,
                  Va.
                  • 6. Re: Calling custom CF tag from javascript
                    Level 7
                    No worries: an awful lot of people don't initially "get" the sequence of
                    events which take place to get CF-driven HTML down to the web browser.

                    That's not to say you can't do what you want to do, I should think.

                    One can make calls back to the server "in the background" of the browser
                    page, using one of a few techniques. The one with the best buzzword is
                    "AJAX". It's perhaps worth googling about the place for some info on that.
                    It's JavaScript technology, not CF technology, so these forums aren't the
                    best place for discussion on that. I'm sure there'll be plenty of AJAX
                    forums out there...

                    --
                    Adam
                    • 7. Re: Calling custom CF tag from javascript
                      BKBK Adobe Community Professional & MVP
                      > ... call a custome cf tag from javascript...
                      > ...Press button, call tag to export to excel ...

                      Doing it with Javascript defeats the purpose of a custom tag. A custom tag is your own custom Coldfusion tag, hence to be used as a tag in a cfm or cfc page. I would instead have Javascript open the cfm page directly, thus

                      <html>
                      <head>
                      <title>Opening excel page with Javascript</title>
                      <script type="text/javascript">
                      function openIt () {
                      window.open("excelExport.cfm","_blank","height=300,width=500,status=yes,menubar=yes,resiz able=yes,scrollbars=yes");
                      }
                      </script>
                      </head>
                      <body>
                      <FORM>
                      <BUTTON name="btn" onclick="openIt();">open it</BUTTON>
                      </FORM>
                      </body>
                      </html>


                      excelExport.cfm
                      ================
                      <cfheader name="Content-Disposition" value="attachment; filename=testPage.xls">
                      <cfcontent type="application/vnd.msexcel" file="C:\CFusionMX7\wwwroot\testPage.xls">

                      Here follows code that does it the custom tag way. You will get the feel of redundancy immediately.