Strange Behavior of ColdFusion Variable [closed] - variables

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am utilizing Bootstrap tabs to display some data in my ColdFusion project. I am attempting to loop through a list of classes that are returned from the database and then getting information based on that class. Here is the snippet of code that applies to my question:
<div class="tab-content" id="class-tabs-content">
<cfset allClassIDs = ValueList(classes.class_id)>
<cfset numOfClasses = ListLen(allClassIDs)>
<cfloop from="1" to="#ListLen(allClassIDs)#" index="i">
<cfset myIndex = ListGetAt(allClassIDs, i)>
<cfoutput>
<div class="tab-pane fade<cfif i EQ 1> show active</cfif>" id="panel-#myIndex#" role="tabpanel" aria-labelledby="tab-#myIndex#">
<!--- The following returns a cfquery --->
<cfset items = CreateObject("component", "com.modules.reels").getInventoryByDivisionAndClass("query", division.location_id, myIndex)>
#items.RecordCount# <-- CODE FAILS ON THIS LINE WITH MESSAGE "variable [ITEMS] doesn't exist"
</div>
</cfoutput>
</cfloop>
</div>
UPDATE: I tried a simpler example of what I was trying to do, and I got the same error: variable [ITEMS] doesn't exist. Here is the simplified code block I tried:
<cfset classes = CreateObject("component", "com.modules.reels").getClasses("query")>
<cfset ClassIDs = ValueList(classes.class_id)>
<cfloop from="1" to="#ListLen(ClassIDs)#" index="i">
<cfset ClassID = ListGetAt(ClassIDs, i)>
<cfoutput>
<cfset items = CreateObject("component", "com.modules.reels").getInventoryByDivisionAndClass("query", 3, ClassID)>
<cfdump var = "#items#">
</cfoutput>
</cfloop>
I do not understand what could possibly be going on here! How can the variable not exist when I set it on the previous line and the cfset did not throw an error? Please help!

Thank you to #rrk for your comments. As it turns out (and I feel really stupid), getInventoryByDivisionAndClass() was missing its <cfreturn> statement!

Related

Coldfusion set dynamic columns for query output [duplicate]

This question already has answers here:
Dynamic Variable Naming and Reference (ColdFusion)
(2 answers)
Getting complex object error when trying to output query values
(1 answer)
Closed 6 years ago.
I am trying to set dynamic query column headers to get their values from a query.
<cfoutput query="qryGetData">
<cfloop from="-18" to="18" index="i">
<cfif i GTE 0>
<cfset variables["target_MonthPlus_#abs(i)#"] = "Testing" />
<td>
<cfoutput>#variables["target_MonthPlus_#abs(i)#"]#</cfoutput>
</td>
<cfelse>
<cfset variables["target_MonthMinus_#abs(i)#"] = "Testing" />
<td>
<cfoutput>#variables["target_MonthMinus_#abs(i)#"]#</cfoutput>
</td>
</cfif>
</cfloop>
Code I have does not really work, I found it from another answer and I have tried all I can think of and tried using EVALUATE() even though I know I should not use.
So basically my query has 37 month fields starting from target_MonthMinus18 to target_MonthMinus1. And then target_MonthPlus0 to target_MonthPlus18. I have taken care of that plus and minus with the CFIF as you can see above. So only other thing different is that value of the month.
Closest things I have got to actually name the columns dynamically is something like this, but this just outputs the name of the column, which would return target_MonthPlus0, target_MonthPlus1, targetMonthPlus2, etc.
But I need to use that name to return the actual value of the columns from the query.
<cfif i GTE 0>
<cfset monthInLoop = "target_MonthPlus_" & #ABS(i)#>
<td>
<cfoutput>#monthInLoop#</cfoutput>
target_monthMinus18 is a column name that may return a value of 100 from qryGetData that I need to display in its td
target_monthMinus17 is a column name that may return a value of 95 from qryGetData that I need to display in its td
target_monthPlus17 is a column name that may return a value of 205 from qryGetData that I need to display in its td
and so on...We are always going back 18 months in the past and 18 months in future as you can tell.
I have found several questions similar to this and have applied to my code but somehow they are trying to do different things or I still do not understand what I am doing wrong.
Thanks in advance for your help :)
PC
I think you may be over thinking this. You can access your columns directly from within the query using something like this:
<cfloop query="qryGetData">
<cfloop from="-18" to="18" index="i">
<cfif i GTE 0>
<td>
<cfoutput>#qryGetData["target_MonthPlus_" & abs(i)][currentrow]#</cfoutput>
</td>
<cfelse>
<td>
<cfoutput>#qryGetData["target_MonthMinus_" & abs(i)][currentrow]#</cfoutput>
</td>
</cfif>
</cfloop>
</cfloop>
This takes advantage of CF's query array syntax. Keep in mind you also have qryGetData.columnlist to work with (a list of all your columns). You might be able to work with that creatively as well.

Coldfusion URL variable changes unexpectedly

I have an issue that is greatly vexing me. I have written a basic pagination tool for a page that is running on Coldfusion 11: http://fftoolbox.scout.com/ffwc/rankings.cfm?rankings=season&page=2
I have designed it such that there is a url query called page that holds the page number. This way, the user can just type in the page number that he desires rather than having to press the next and previous buttons.
The pagination works just fine for pages 1 - 25, but on page 26 and after, it records the url.page variable as 1, even though the link on the control clearly shows that the variable should be page 26.
If you will notice, I have coldfusion dumping the URL scope at the top of the page. You will note that when the page is equal to 25 or less, the page is reported correctly. Any value over 25, though, url.page is assigned a value 1, even though that is not what is being sent according to the browser. I have tested this in FF, Chrome, and IE, and all exhibit the same behavior. This leads me to believe that it is not something in the code or a browser based peculiarity, but possibly some sort of server setting.
Here is some assorted code of the project:
The dump and setting the session variables.
<cfdump var='#url#'>
<cfif not StructKeyExists(url,'page')>
<cfset session.page = 1>
<cfelse>
<cfset session.page = url.page>
</cfif>
<cfset startingRank = (session.page - 1)*50 +1>
<cfset endingRank = (session.page - 1)*50 +50>
This starting and ending rank are used in an SQL query to retrieve the proper range of players. I am not including the SQL unless someone requests it as that is working fine. In fact, when I hard code the url.page to be 26, everything works as it is supposed to.
The Previous and Next links:
<tr><td colspan='2' style='text-align: center'>
<cfif session.page gt 1>
<a href='./rankings.cfm?rankings=season&action=#Evaluate(session.page - 1)#'>Previous</a>
</cfif></td>
<td colspan='2' style='text-align: center'>
<cfif session.page lt Evaluate(Int((GetMax.recordCount -1)/50) +1)>
<a href='./rankings.cfm?rankings=season&page=#Evaluate(session.page + 1)#'>Next</a>
</cfif></td></tr>
Please let me know if you need any more information. I am thinking that this is actually either an Apache issue or a CF one as the pagination is working properly on pages 1 through 25.
EDIT:
I have had a request to show the queries. There are two of them. One to get the data and another to get the count of the entire set of data.
<cfquery name='GetData' datasource='XXXXXXXX'>
select * from
(select #currentRank := #currentRank +1 as rank,player_name, point_sum, contest_type from
(select player_name,sum(points) as point_sum, contest_type, (select #currentRank := 0) r
from 2014_ranking_season
inner join ecom_item_type on ecom_item_type.ecom_item_type_id = 2014_ranking_season.contest_type
where contest_type = #session.filter#
group by player_name)t1
order by point_sum desc)t2
where rank between #startingRank# and #endingRank#
</cfquery>
<cfquery name='GetMax' datasource='XXXXXXXX'>
select * from
(select #currentRank := #currentRank +1 as rank,player_name, point_sum, contest_type from
(select player_name,sum(points) as point_sum, contest_type, (select #currentRank := 0) r
from 2014_ranking_season
inner join ecom_item_type on ecom_item_type.ecom_item_type_id = 2014_ranking_season.contest_type
where contest_type = #session.filter#
group by player_name)t1
order by point_sum desc)t2
</cfquery>
I hope that helps. Please bear in mind that except for the previous button with which I am experimenting, everything works fine until page > 25.
EDIT:
The value for GetMax.recordCount = 2242. Also, I am writing a small reproduction page that is scaled down to just produce the results. Once it is done, I will post the code of the entire page. Whether or not it reproduces the result it will tell us SOMETHING.
EDIT:
The reproduction page is in place and the error IS reproducible, even with the scaled down code. Here is the URL: http://fftoolbox.scout.com/ffwc/testPagination.cfm?rankings=season&page=26
Here is the entire code listing:
<cfdump var='#url#'>
<cfset session.page = 1>
<cfif StructKeyExists(url,'page')>
<cfset session.page = url.page>
</cfif>
<cfset startingRank = (session.page - 1)*50 +1>
<cfset endingRank = (session.page - 1)*50 +50>
<cfif not StructKeyExists(session,'filter')>
<cfset session.filter = 0>
</cfif>
<cfparam name="url.rankings" default="season">
<html>
<head>
<title>Test Pagination</title>
</head>
<body>
<br /><br />
<cfoutput>
<table width='99%' cellpadding='5' cellspacing='0'><tr class='header'>
<cfset count = 0>
<cfquery name='GetData' datasource='fftoolbox_sql'>
select * from
(select #currentRank := #currentRank +1 as rank,player_name, point_sum, contest_type from
(select player_name,sum(points) as point_sum, contest_type, (select #currentRank := 0) r
from 2014_ranking_season
inner join ecom_item_type on ecom_item_type.ecom_item_type_id = 2014_ranking_season.contest_type
group by player_name)t1
order by point_sum desc)t2
where rank between #startingRank# and #endingRank#
</cfquery>
<cfquery name='GetMax' datasource='fftoolbox_sql'>
select * from
(select #currentRank := #currentRank +1 as rank,player_name, point_sum, contest_type from
(select player_name,sum(points) as point_sum, contest_type, (select #currentRank := 0) r
from 2014_ranking_season
inner join ecom_item_type on ecom_item_type.ecom_item_type_id = 2014_ranking_season.contest_type
group by player_name)t1
order by point_sum desc)t2
</cfquery>
<th>RANK</th><th>PLAYER NAME</th><th>TEAM NAME</th><th>POINTS</th></tr>
<cfloop query='GetData'>
<cfquery name='GetOneName' datasource='fftoolbox_sql'>
select team_name
from 2014_ranking_season
where player_name = <cfqueryparam cfsqltype='CF_SQL_VARCHAR' value='#GetData.player_name#'>
limit 1
</cfquery>
<cfset name = URLEncodedFormat(#player_name#)>
<tr <cfif #count#%2 eq 0>class='evenRow'<cfelse>class='oddRow'</cfif>><td>#rank#</td>
<td><a href='./player.cfm?name=#variables.name#' target='_blank'>#player_name#</a></td><td>#GetOneName.team_name#</td><td>#point_sum#</td></tr>
<cfset count++>
</cfloop>
<tr><td colspan='2' style='text-align: center'>
<cfif session.page gt 1>
<a href='./testPagination.cfm?rankings=season&page=#Evaluate(session.page - 1)#'>Previous</a>
</cfif></td>
<td colspan='2' style='text-align: center'>
<cfif session.page lt Evaluate(Int((GetMax.recordCount -1)/50) +1)>
<a href='./testPagination.cfm?rankings=season&page=#Evaluate(session.page + 1)#'>Next</a>
</cfif></td></tr>
</table>
</cfoutput>
</body>
</html>
I will also get the http request headers to display on that page. I will put them in the question, if people want, but the question is starting to get long, and the cfdump formats it nicely in the browser. Thank you, everyone for the interaction so far.
UPDATE:
I am suspecting that our provisioning team, over whom I have no control, might have done something on the backend, such as put it on Varnish, which is not supposed to happen. Please continue to look at the code, etc, and I will bark up this tree to see if there is something they have done. 25 just seems like to "human" a number for it not to be a setting somewhere. I will keep you posted.
UPDATE:
I have checked with the provisioning team, and Varnish is not active, and the load balance is NOT causing the issue, as I could replicate the issue when bypassing the LB. My opinion that it is a configuration issue with Apache or CF seems to be becoming more and more likely as we rule things out.
UPDATE:
Upon adding the code that #Leigh recommended, we find that the http request is definitely page=26, and the URL scope is definitely page=1. I am looking to see if an Application file might be messing with it.
FINAL UPDATE:
Upon examining the Application.cfm, I found the following code:
<cfif cgi.script_name NEQ "/ffwc/all-time-leaderboard.cfm">
<cfset ValidPages = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25">
<cfif IsDefined("url.page") and ListFind(ValidPages,url.page) eq 0>
<cfset url.page = 1>
</cfif>
</cfif>
After this was commented out, the pagination worked just fine. Another alternative method of making it work would be to not use page as the variable name for the page. (This is counter intuitive and distasteful to me) I hold the opinion that constructs like pagination should be contained within one file or directory, and not be site wide.
Upon examining the Application.cfm, I found the following code:
<cfif cgi.script_name NEQ "/ffwc/all-time-leaderboard.cfm">
<cfset ValidPages = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25">
<cfif IsDefined("url.page") and ListFind(ValidPages,url.page) eq 0>
<cfset url.page = 1>
</cfif>
</cfif>
After this was commented out, the pagination worked just fine. Another alternative method of making it work would be to not use page as the variable name for the page. (This is counter intuitive and distasteful to me) I hold the opinion that constructs like pagination should be contained within one file or directory, and not be site wide.
Thank you to all that commented, and helped me in this endeavor.
First of all, your "previous" button isn't setting a URL.page or session.page - it's using "action." Since page isn't defined in the URL it automatically sets the page to one... So clicking "previous" and then "next" always sets me back to page 2 no matter where I start.
Now, your "next" link...
<cfif session.page lt Evaluate(Int((GetMax.recordCount -1)/50) +1)>
<a href='./rankings.cfm?rankings=season&page=#Evaluate(session.page + 1)#'>Next</a>
</cfif>
I just ran this code after setting session.page on my own .cfm page...
A "Next" button will only ever show up if session.page is zero or GetMax.recordcount is more than 50x the value of session.page. I raise issue with that because GetMax.recordcount shouldn't ever change. You're displaying 50 records at a time.
The following code doesn't work so I don't what you're doing on your end...
<cfset GetMax.recordcount = 50>
<cfset session.page = 1>
<cfoutput>
<cfif session.page lt Evaluate(Int((GetMax.recordCount -1)/50) +1)>
<a href='./rankings.cfm?rankings=season&page=#Evaluate(session.page + 1)#'>Next</a>
</cfif>
</cfoutput>
It might be time to show us the query logic.
Edit:
Why not do something like this?
<cfset StartRecord = #url.page# * 50 - 49>
<cfquery name="listOfPeople" datasource="XXX">
SELECT TOP 50 *
FROM PeopleTable
WHERE PeopleID >= #StartRecord#
</cfquery>
It's so simple and I'm just not getting why the query GetMax is needed. All that extra math involved just heightens the risk for error. Pagination shouldn't be a project unto itself.

ColdFusion Query Output Displaying Variable Name Instead Of Field Value

I'm an "old dog" and largely self-taught on this stuff and can usually make things work (primative and convoluted as it might be), but this is the first thing that has me really stymied.
I didn't want to burden everyone with a lot of stuff to try to explain, but, here is perhaps a better explanation and example:
(#Leigh - and thank you for your time and help!) - The query is dynamic because what I desire to have is a single "universal" page combination (form page plus accompanying action page) that is used to edit multiple different (but fairly similar) record sets (so that I don't have to write a whole bunch of individual form/action page pairs).
When this "universal" "change" form page is invoked, it is passed the "ID" variable for the particular record to be edited, along with a "listID" variable unique to the particular record set containing the record to be edited.
Using the "URL.listID", the form page then looks at a pre-defined included list of record set variables (datasource, query table, field for column 1, field for column 2, etc.) pertaining to the value of the "listID" and sets (using ) the dynamic variables. Example - if "listID" is "5", which has only one column:
<cfif #URL.listID# EQ 5>
<cfset page_title = 'Change Member Role Picklist'>
<cfset datasource = '#Session.db_docs#'>
<cfset query_tbl = 'tblMemberRole'>
<cfset columns = 1>
<cfset column1_label = 'Member Role'>
<cfset column1_field = "role">
<cfset column1_input_type = "text">
<cfset column1_input_size = "100">
<cfset column1_input_maxlength = "100">
</cfif>
The query uses those variables ("ID" plus the others it got from the above list) to retrieve the individual record to be edited, and populate the "change" form.
Run query:
<cfquery name="cfqGetItem" datasource="#datasource#">
SELECT *
FROM #query_tbl#
WHERE ID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer">
</cfquery>
My "change" form (abbreviated here without table HTML) to be populated would be:
<form name="form_item_chg" action="chg_item2.cfm" method="post" enctype="multipart/form-data">
<input type="text" name="#column1_field#" maxlength="#column1_input_maxlength#" size="#column1_input_size#" value="#cfqGetItem[column1_field][currentRow]#">
<input type="Submit" value="Post Changes">
</form>
However, instead of the "change" form being populated with the VALUE for field "role", it instead is trying to use the variable name "column1_field", which it says is (true, of course) undefined in the query.
When I tried "#cfqGetItem[column1_field][currentRow]#", it says "Variable currentrow is not defined".
When I tried "#cfqGetItem.column1_field#", it says "Element column1_field is not defined in query cfqGetItem".
I apologize in advance for not knowing/using all the correct terminology, and hope I am explaining this reasonably clearly. I suspect I will have to revert to writing individual form-page/action-page pairs. Thank you to all for your time and help!
ORIGINAL POST:
I'm not highly technical, and this is probably something simple, but here is
my dilemma, where I am attempting to retrieve a single record using a variable name in the query.
First, I define some variables:
<cfset ID = #Form.ID#<!--- the single record I want to retrieve, passed from a form --->
<cfset datasource = 'MyDatabase'>
<cfset query_tbl = 'MyDatabaseTable'>
<cfset field1 = 'actual_fieldname1'><!--- field in MyDatabaseTable --->
<cfset field2 = 'actual_fieldname2'><!--- field in MyDatabaseTable --->
ETC.
Then, to retrieve this single record, I run a query using those variables:
<cfquery name="cfqGetItem" datasource="#datasource#">
SELECT *
FROM #query_tbl#
WHERE ID = #ID#
</cfquery>
Then, I attempt to display the query output:
EITHER AS
<cfoutput>
<p>#cfqGetItem.field1#
<p>#cfqGetItem.field2#
</cfoutput>
OR, AS
<cfoutput>
<p>#cfqGetItem[field1][currentRow]#
<p>#cfqGetItem[field2][currentRow]#
</cfoutput>
In each case, I get a similar CF error message: "Element field1 is not defined in query cfqGetItem", or "Variable currentrow is not defined".
How can I get the query output to generate the actual values for the record instead of the variable names?
Thank you very much for any help!
If you change this:
<cfoutput>
<p>#cfqGetItem[field1][currentRow]#
<p>#cfqGetItem[field2][currentRow]#
</cfoutput>
to this:
<cfoutput>
<cfloop query="cfqGetItem">
<p>#cfqGetItem[field1][currentRow]#
<p>#cfqGetItem[field2][currentRow]#
</cfloop>
</cfoutput>
You should be ok. However, this is the simplest way
<cfoutput query="cfqGetItem">
<p>#actual_fieldname1#
<p>#actual_fieldname1#
</cfoutput>
Setting the table and field names to variables complicates matters. Unless they really can vary, don't do it. Also, the cfqueryparam tag is your friend. Use it in places like this:
where id = <cfqueryparam
cfsqltype = "cf_sql_integer"
value = "#id#">
You can try out like this also:
<cfquery
name="GetParks" datasource="cfdocexamples"
>
SELECT PARKNAME, REGION, STATE
FROM Parks
ORDER BY ParkName, State
</cfquery>
<cfoutput>
<p>#GetParks.PARKNAME#
<p>#GetParks.REGION#
</cfoutput>
<cfoutput >
#GetParks['state'][GetParks.RecordCount]#
</cfoutput>
<cfoutput >
#GetParks['state'][2]#
</cfoutput>

ColdFusion - Nested Variable (dynamic variable read) [duplicate]

This question already has answers here:
Coldfusion - variable field name when looping through database query results
(2 answers)
Closed 9 years ago.
Edit: The QUESTION is a duplicate, but the ANSWER is not!
I have the following code:
<cfquery name="contact" datasource="thesource">
SELECT * FROM #table# WHERE foo = '#bar#'
</cfquery>
and then later on (this is the problem part):
<cfloop from="0" to="9" index="i">
<cfset thisvar = Evaluate("contact.check" & i) />
<cfoutput>
#thisvar#
</cfoutput>
</cfloop>
Upon execution, it throws a nice big "Variable contact.check0 is Undefined". However, #contact.check0# will output just fine if hardcoded.
Any ideas on how to fix this?
Note:
I have seen Coldfusion - variable field name when looping through database query results, and although the problem seems to be exactly the same, the solutions do not work. As per the comments, I am also getting a "cannot be converted to a number" error. I notice Tomalak mentions "a little catch", but never says what it is. In the article he links to, I have tried every syntactically equivalent form, and it all throws an error...either cannot convert to a number or is not defined.
Also, I'm aware Evaluate() has overhead and "should not be used". I'll take any solution that works, whether it has Evaluate in it or not.
This is on ColdFusion 9.
Thank you
Edit: while a similar question already had an answer, this question had a different cause. See accepted answer below.
First of all, standard blub about escaping inputs. cfqueryparam exists for a reason. That aside you can do this without evaluate. Give this a try instead, including a check to make sure there is actually a result
<!--- make sure that there is actually a result --->
<cfif contact.RecordCount EQ 0>
NO RESULT
<cfelse>
<cfloop from="0" to="9" index="i">
<!--- assumes that you want row 1 --->
<!--- check.CurrentRow could also be used instead of 1 --->
<cfset thisvar = contact['check'&i][1] />
<cfoutput>
#thisvar#
</cfoutput>
</cfloop>
</cfif>
I suspect that it is attempting to Evaluate the column without specification of the row number, while when hard-coding it you'll find it uses the current row.
edit as Dan Bracuk pointed out this is an exact duplicate of the question you linked in your question, Coldfusion - variable field name when looping through database query results
This is ridiculous and absurd. Working code (moved things around a bit):
<cfoutput>
<cfloop from="0" to="9" index="i">
<cfset thisvar = contact["check"&i][1] />
#thisvar#
</cfloop>
</cfoutput>
NOT working code:
<cfoutput query="contact"> <!--- this line here --->
<cfloop from="0" to="9" index="i">
<cfset thisvar = contact["check"&i][1] />
#thisvar#
</cfloop>
</cfoutput>
Someone else had put cfoutput tags around the whole page. While this normally wouldn't be a problem, they ALSO declared the query attribute. This somehow overwrote the original query from the db. Calling contact.check0 worked just fine, but building the variable name dynamically, I think, was attempting to reference the cfoutput's query attribute.
Thanks to Peter Boughton for the suggestion to extract the problem code...which led me to this realization, and Simon for posting the syntactically correct code. Points go to them.

How to output variables dynamically in ColdFusion

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 Variables scope, so you can do:
<cfset StaticValue="DynamicValue">
<cfset DynamicValue="What I Want To Show">
<!--- outputs value of Variables.DynamicValue --->
<cfoutput>#Variables[StaticValue]#</cfoutupt>
(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.
First of all, this is wrong:
<cfoutput>#<span id="demo"></span>#</cfoutput>
You are suggesting that there is a CF variable named
<span id="demo"></span>
Your question isn't clear, so neither can be my answer, but I suspect that you are trying to do this:
<script type="text/javascript">
<cfoutput>
document.getElementById("demo").innerHTML="#StaticValue#";
</cfoutput>
</script>
<span id="demo"></span>
When this JavaScript runs on the page, the string "DynamicValue" will be written into the span#demo.
Are you trying to compare if they are the same and then display it if they are?
<cfset StaticValue="DynamicValue">
<cfif staticvalue is dynamicvalue>
<cfset DynamicValue="What I Want To Show">
<script type="text/javascript">
<cfoutput>
document.getElementById("demo").innerHTML="#DynamicValue#";
</cfoutput>
</script>
</cfif>
Not sure what u are trying to do here - as this will error on bad variable inside your # #
<cfoutput>#<span id="demo"></span>#</cfoutput>
Should be:
<cfoutput>
<span id="demo">
#dynamicvalue#
</span>
</cfoutput>
If you are just trying to get a url to display:
<cfoutput>
<span id="demo">
#dynamicvalue#
</span>
</cfoutput>