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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Something related to "unterminated string constant" error

Status
Not open for further replies.

lcs01

Programmer
Aug 2, 2006
182
US
One of my company's page contains a line like this:

Code:
function printTitle() {
  parent.searchTermsPane.document.write("<script>function hideIt(aControl) {alert(aControl.name);}[b]</script>[/b][COLOR=blue]/* some implementations omitted here */[/color]");
}

The page has worked well since day one. However, since last week, this page was suddenly broken on our development server only. The browser keeps complaining that there is runtime error "unterminated string constant". But it still works fine on both live server and QA server.

So I made a change like this:

Code:
function printTitle() {
  parent.searchTermsPane.document.write("<script>function hideIt(aControl) {alert(aControl.name);}[b]<[COLOR=red]\[/color]/script>[/b][COLOR=blue]/* some implementations omitted here */[/color]"); }

then the error is gone.

I understand why the fix worked. But I don't not understand why it worked before and it still works on live and QA server w/o this fix.

Could someone kindly explain it to me? Many thanks!
 
Try using CDATA statements inside your script tags:

Code:
<script type="text/javascript">
// <![CDATA[

    function printTitle() {
        // ...
    }

// ]]>
</script>

as it may well be the parser thinks that the script element is being closed before the string.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi

Strange. The proper old fashion workaround is to cut the string, so the parser does not recognize the tags :
Code:
function printTitle() {
  parent.searchTermsPane.document.write("<s[red]"+"[/red]cript>function hideIt(aControl) {alert(aControl.name);}</s[red]"+"[/red]cript>[gray]/* some implementations omitted here */[/gray]"); }
Notice the word I used : "workaround". So go ahead and use Dan's solution.

Feherke.
 
Thank you, Dan and Feherke.

The page has already had the tags that Dan suggested, i.e.
the pair -- '// <![CDATA[' & '// ]]>'.

It really puzzles me why it only happens on dev server but not on live/QA servers. I have made sure that no one in my company has changed any configuration/initial setups on the dev server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top