ColdFusion vs. JavaScript

When a browser requests a page from a web server with a .cfm extension, the Web Server passes that page onto the ColdFusion engine for processing. At that point, ColdFusion processes all the CFML code - leaving all HTML and JavaScript - and passes the results back to the Web Server, which in turn returns the results back to the browser. The browser translates the the HTML and JavaScript and displays the page.

Because of this process, the ColdFusion engine has no knowledge or concern about JavaScript and HTML. That code is only processed by the browser and is completely ignored on the server.

For this reason, you cannot have ColdFusion code dependent on a JavaScript function, like processing a CFQUERY tag based on some JavaScript conditional logic. The CFQUERY tag will always be processed on the server regardless of what JavaScript logic was placed around it.

JavaScript can be dynamically created using ColdFusion, just as you create HTML code using ColdFusion, like creating table rows by looping over the results of a query. Using ColdFusion logic, you can determine what JavaScript is sent back to the browser.

Passing values back and forth between ColdFusion and JavaScript requires some thought as well. Because ColdFusion can only process a variable/value when a page is processed on the server, a page call must happen. You can pass JavaScript values to ColdFusion using URLs, form fields (including hidden form fields) and by using frames or hidden frames. ColdFusion variables can be passed to JavaScript simply by using CFOUTPUT tags within the section of JavaScript you are creating to send back to the browser.


Join Our E-Mail Newsletter

For Email Newsletters you can trust

Sister Sites

RiteTech LLC
Modern HOA