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

Unterminated string constant Code 0

Status
Not open for further replies.

NewbiDoobie

Technical User
Jul 25, 2005
63
US
I have this little bit of code that is throwing me for a loop.

I looked up what the error said, but do not see where this has not been terminated. If I take this code out, the page works fine.

If I leave it in I get:

Line 100
Char 25
Error: unterminated string constant
Code 0

If I take out the javascript I still get the error, but if I take out the whole section I do not

<span id="browsertest1" style="position:relative"> Testing Your Browser...</span>
<!--<script language="JavaScript">
var temp1 = "browsertest1";
var temp2 = "Testing Your Browser...Failed";
setTimeout("ChangeText(temp1, temp2)",5000);

</script>-->
 
what comment code? I am sorry, but I copied this from the previous version of the page and am still unsure what it does other than displays the message as it starts the page and then disapears.

The change text function is this:
Code:
	function ChangeText(ElementID, newtext) 
		{
			var targetElement1 = getElementGeneric(ElementID);
			
			if (newtext == "" && targetElement1.style.display == "") 
			{
				targetElement1.style.display = "none";
			}
			else
			{
				targetElement1.style.display = "";
				targetElement1.innerText = newtext;
			
			}
		
		}

Is there something wrong with the span statement? The javascript does not seem to do anything on my browser as I have added alerts and they do not show.
 
Try this:

setTimeout("ChangeText('" + temp1 + "','" + temp2 + "')",5000);

Lee
 
I think this will fix it for you:
Code:
 function ChangeText(ElementID, newtext) 
        {
            var targetElement1 = [b]document.[/b]getElement[b]ById[/b](ElementID);
            if (newtext == "" && targetElement1.style.display == "") 
            {
                targetElement1.style.display = "none";
            }
            else
            {
                targetElement1.style.display = "";
                targetElement1.innerText = newtext;
            
            }
        
        }
It was getting upset about your use of getElementGeneric which I guess was a typo somewhere [smile]

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
I would look at coding what you have shown us like this (changing the way you deliver the javascript block, and incorporating the changes I suggest above - and a little tweak to the function [smile]) - hope it works out for you!

Code:
<span id="browsertest1" style="position:relative;"> Testing Your Browser...</span>
<script type="text/javascript">
<!--
var temp1 = "browsertest1";
var temp2 = "Testing Your Browser...Failed";
setTimeout("ChangeText(temp1, temp2)",5000);

function ChangeText(ElementID, newtext) {
  var targetElement1 = document.getElementById(ElementID);
  targetElement1.innerText = newtext;
  targetElement1.style.display = (newtext == "" && targetElement1.style.display == "") ? : "none" : "";
}
//-->
</script>

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
*yawn* I had a typo (and a beer - sorry):
Code:
<span id="browsertest1" style="position:relative;"> Testing Your Browser...</span>
<script type="text/javascript">
<!--
var temp1 = "browsertest1";
var temp2 = "Testing Your Browser...Failed";
setTimeout("ChangeText(temp1, temp2)",5000);

function ChangeText(ElementID, newtext) {
  var targetElement1 = document.getElementById(ElementID);
  targetElement1.innerText = newtext;
  targetElement1.style.display = (newtext == "" && targetElement1.style.display == "") ? "none" : "";
}
//-->
</script>

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top