Hi,
I have this javascript error that I am unable to fix unterminated string constant.
Here is what I am trying to do

  var test = '<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas</p>
          <p>ahdndsa</p>';

          document.getElementById('education').innerHTML = test;

How to fix this error?

Recommended Answers

All 4 Replies

Where the rest of the code? I tried this and there was no error:

<div id='education'></div>

<script>
var test = '<p>rajnas bnas</p><p>ahdndsa</p>';
document.getElementById('education').innerHTML = test;
</script>

You might try running the script through JSLint.

Strings can't span multiple lines. You need to close and concatenate the strings:

var test = '<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas</p>' +
          '<p>ahdndsa</p>';
document.getElementById('education').innerHTML = test;
commented: To the point +12

scrager is correct on declaring a string on multiple lines. A string, however, can contain new line character, and that should not be confused with the multiple line span.

//i.e.
var test = "<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas</p>
            <p>ahdndsa</p>";   // error
var test = "<p>rajnas asdjhsadnmdas dasjads jmsad dasndsaads bnas</p>\n<p>ahdndsa</p>";  // OK
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.