Feb
12Using ColdFusion for Dynamic Server-side JavaScript
Posted By: Brian Meloche; Posted At : February 12, 2007 3:08 PM
Related Categories: ColdFusion, JavaScript, AJAX
Here's a little tip for using a .cfm file for dynamic JavaScript generation.
Need to use JavaScript, but not sure what the JS will actually look like until you build it... but don't want to show the JavaScript on the webpage? I am using Spry for some Ajax style selects, but I need to control the XML on the fly.
Try something like this:
...
<script type="text/javascript" src="/ClientIncludes/DynamicCFJS.cfm?year=#url.year#"></script>
You could then have in your DynanicCFJS.cfm something like this:
<cfoutput>
var dsYears = new Spry.Data.XMLDataSet("/index.cfm?event=buildYearList&year=#url.year#", "carlineYears/year", { useCache: true });
</cfoutput>
Of course, similar techniques will work in any web language. Tailor to the web language of your choice.


There are no comments for this entry.
[Add Comment] [Subscribe to Comments]