Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript with CF

Status
Not open for further replies.

alburaq

Programmer
Dec 23, 2001
10
0
0
PS
I'm trying to make a news tick tape using java script and coldfusion when I use the following code I got an error

var content='<CFOUTPUT query=&quot;show&quot;><cfif #location# is 7 and flag LTE 7><p><a href=&quot;show.cfm?val=#id#&quot;>#title#</a></p><cfset flag=flag+1></CFIF>
</cfoutput>';


The error says: Unterminated string constant

if I replace #title# with any other string or with #id# the script works.

I know that the problem is with the string #title# but what kind of problem is this?? the string title is not more than 100 characters.
 
I would guess that you have got a ' in the title variable. this will make the javascript break as the resulting output will look something like:

var content='<p><a href=&quot;show.cfm?val=1&quot;>it's breaking</a></p>';

javascript is saying that everything after the ' in it's is what is unterminiated as it is taking everything from the first ' to the ' in it's as one value and then everything after as another value. you could try setting all of your above code to a CF variable and then use that

var content = #CFVariable#;

that might work !

 
Make sure there are no line breaks in the output as well -- could be in the title?

to make it a little easier to read, try reformatting it a little:

<CFOUTPUT query=&quot;show&quot;>
<cfif #location# is 7 and flag LTE 7>
<cfset jsVar = '<p><a href=&quot;show.cfm?val=#id#&quot;>#title#</a></p><cfset flag=flag+1>'>
</cfif>
</cfoutput>

<cfoutput>
var content='#jsVAr#';
</cfoutput>

Output the jsVar to screen and see if there is any strange characters, linebreaks, etc in one of your variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top