I am trying to replace a value with a passed value using javascript or coldfusion. The idea is we have a template which outputs values in the grid. But the values displayed need be dynamically determined by a query. So far I haven’t been able to come up with any good ideas.
Here is a sample of something I thought would of work (but does not). It may explain what I am trying to do:
<cfset StaticValue="DynamicValue">
<cfset DynamicValue="What I Want To Show">
<script type="text/javascript">
document.getElementById("demo").innerHTML="<cfoutput>#StaticValue#</cfoutput>";
</script>
<cfoutput>#<span id="demo"></span>#</cfoutput>
To use an existing string/variable as a variable name, you need to use bracket notation.
In CF, if you haven’t explicitly scoped a variable, it is created in the
Variablesscope, so you can do:(This works will all scopes/structs/queries/etc)
NOTE: If the variable is to be output inside of a JavaScript string, you need to wrap it in
JsStringFormat(...)to ensure the appropriate characters are escaped.