0

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?

5
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Taywin
0

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>

Edited by JorgeM

1

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;
Votes + Comments
To the point
0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.