views:

81

answers:

3

Is it possible to call a jQuery function from within a ColdFusion switch statement? If so, how?

+2  A: 

No. ColdFusion runs on the server. jQuery runs on the client (the browser). You can conditionally output (depending on which case you hit) JavaScript code that will call the jQuery function.

Matthew Flaschen
Right, I'd want it to run the jQuery function after the page renders.
George
+4  A: 

You do know that you are mixing client and server side code? That said it is really not an issue to do:

<script language="javascript">
    <cfswitch expression="#n#">
      <cfcase value="test1">
        $.something1()
      </cfcase>

      <cfcase value="test2">
        $.something2()
      </cfcase>
    </cfswitch>
</script>
Nick
+1  A: 

Short answer is No. As Mathew explained, CF and JS are running in separate places, and any attenpt to make them both work together would be frustrating.

I for one think that there will be no reason to run javascript code from the serverside, as you can simply run your javascript code on the page load.

You might be trying to accomplish something simpler than you think, and a simple

 $(document).ready(function(){
   // Your code here
 });

Might actually do exactly what you need. I don't know what you're trying to accomplish, but if you say exactly what it is, we might try and help you.

Cheers

Marcos Placona