The concept that took me awhile to get my head around.  You don't usually pass variables to _javascript_ in examples like this.  If you need to truly pass variables to _javascript_ from CFML you need to use some kind of intermediary technology such as WDDX.  But for what you seem to be trying to do, you just need to create some dynamically written _javascript_.  This works just like dynamically written HTML that we all do on a daily basis.  All the CFML mixed with _javascript_ code is rendered in the server and the completed _javascript_ is sent to the client where it is ran.  Some basic examples:


To create a list of links with a dynamic _javascript_ phrase:


<cfoutput query="aQuery">
    <a href="" > </cfoutput>


A gotcha in this syntax is the mixing of quotes on the onClick property.  If you want the parameter of the JS function to be a string literal wrapped in quotes and the onClick property to be correctly wrapped in quotes you must properly nest double (") and single (') quotes.  Also, if the JS complains about the string #aQuery.aColumn#, then the CFML variable was not rendered, which means that is was not inside <cfoutput> tags for some reason.


To create a dynamically generated JS function:


<script>


function aJSfunction ( foo, bar )
{
    var sampleArray = new Array(1);


    <cfoutput query="aQuery">
        sampleArray[currentRow] = "#aQuery.aColumn#";
    </cfoutput>
}
</script>


This would create a simple JS array out of the values in a column from a CFML query.  This could also be done with WDDX if one so desired.  If you are using a Macromedia IDE such as Studio, Homesite or Dreamweaver, the color coding feature gets confused with this kind of mixing of JS and CFML code, but that has no bearing on the correctness of the code so just ignore the strange coloring of the code.


HTH


If you are still unsure of how to accomplish your requirements and if you can provide a couple of snippets of your actual code we can probably help you more specifically with your syntax.


--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA

"C code. C code run. Run code run. Please!"
     - Cynthia Dunning
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to