4 Replies Latest reply on Sep 6, 2006 7:07 AM by Newsgroup_User

    CF and JS integration

    Dinghus Level 1


      I'm wondering if CF can use a variable passed by JavaScript.

      Like I have an text box and when something is entered into it, a function is called. I'm wondering if I can grab that value and put it in a CF variable?

      function checkIt(L) {
      <cfset myVariable = L.value>
      }

      doesn't work obviously. Any answers to this?

      What I am trying to do is make a quiz with the answers checked as soon as they are entered. But I don't want the answers viewable in view source of the page. So if I can change the variable to a CF variable I can compare it to the array of answers without it showing up on the view source in the JavaScript.
        • 1. Re: CF and JS integration
          Dan Bracuk Level 5
          Cold Fusion runs on the server and js runs on the client. So, no.

          Unless you can do something with Ajax. I know it's out there but I've never worked with it.
          • 2. Re: CF and JS integration
            Dinghus Level 1
            I was thinking of CFSCRIPT. I realized after posting that message that it would appear exactly what you said. Obviously CF can't directly read JS since it is server side and JS is client side.

            Gotta be a way of hiding the answers from the user. Guess I could just use Flash. :)
            • 3. Re: CF and JS integration
              Mr Black Level 1
              You can pass a value from JS to CF. You need to set some form or URL variable value, so it will be passed to the server on submit.
              • 4. Re: CF and JS integration
                Level 7
                I was thinking of CFSCRIPT. I realized after posting that message that
                it would appear exactly what you said. Obviously CF can't directly read
                JS since it is server side and JS is client side.

                Gotta be a way of hiding the answers from the user. Guess I could
                just use Flash. :)

                What you want to do is rather advanced, but it is possible. Your
                choices basically break down as follows.

                1) Use JS to populate form or URL values that are submitted to CF and a
                result is returned. This would require pages to be submitted and refreshed.

                2) Use frames, inline or otherwise, to submit the data and return the
                results. Takes some good JS to pass data into and out of frame pages.
                This would only require one small, potentially hidden section of the
                page to refresh.

                3) Use AJAX, basically number 2 taken to the next level. Now you are
                using JS response headers to send data back and forth. There are
                several CF-Ajax projects available to make this fairly easy to do. But
                some exploration would be required.

                4) Use Flex, Flash front end, ColdFusion back end. Some really cool
                stuff can be done here. Lots of learning if you have not tried it
                before, but everything you need to play with this is free for the
                download from Adobe.

                5) Standalone Flash. Build it all as a Flash movie.

                That is what I can think of. HTH