Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have this javascript error that I am unable to fix unterminated string constant.
Here is what I am trying to do
JavaScript
var test = '<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas</p>
        <p>ahdndsa</p>';
        document.getElementById('education').innerHTML = test;

How to fix this error?
Posted
Updated 27-Oct-12 10:07am
v2

As I see, you try to use multiline string literal. That's not so straightforward, as it seems.
Look here: http://www.componentart.com/community/blogs/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx[^]
This is also an alternative: http://forums.whirlpool.net.au/archive/487804[^]
 
Share this answer
 
v2
A string constant is missing a closing quotation mark. String constants must be enclosed within a pair of quotation marks.
Refer: MSDN: JS1015: Unterminated string constant[^]

Try:
JavaScript
var test = "<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas" + "\n" +
         "<p>ahdndsa</p>"
         document.getElementById('education').innerHTML = test;
 
Share this answer
 
Hi I copied and pasted your code in my text.aspx file syntax is given below, and it worked fine when I wright the whole statment
JavaScript
var test = '<p>rajnas asdjhsadnmdas dasjads bnas</p><p>ahdndsa</p>'; 

in a single line, but if i write below line
HTML
<p>ahdndsa</p>'; 

in new line then only its giving unterminated string constant error .

so try to put (var test) value in a single line as in below code . Hope it will do.


XML
<script>
   function aa()
   {
var test = '<p>rajnas asdjhsadnmdas dasjads bnas</p><p>ahdndsa</p>';
         document.getElementById('education').innerHTML = test;

         }
   </script>




XML
<body>
<a href="#" onclick="aa()">click</a>
    <div id="education">
    </div>
</body>


[Edit]Code block added[/Edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900