Double quote in JavaScript string
Solution 1:
Use single quotes.
error += '<li> this is not the name "....." </li>\n';
Or escape the double quotes.
error += "<li> this is not the name \".....\" </li>\n";
Solution 2:
Use single quotes as your string delimiters:
if (i == 0) {
error += '<li> this is not the name "....." </li>\n'
}
If you have single quotes in the string, delimit it with double quotes.
If you have double quotes in the string, delimit it with single quotes.
If you need to use both types in the string, escape whatever delimiter you have chosen by prefixing it with a \
.
Solution 3:
Consider to use the default entity
"
Solution 4:
error += "<li> this is not the name “.....” </li>\n"
Or, if you use a variant of English where single quotation marks are the norm, as usual in British English,
error += "<li> this is not the name ‘.....’ </li>\n"
Using proper punctuation marks, you won’t encounter problems with the quoting conventions of JavaScript. Computer languages use ASCII quotes, human languages don’t.
Just make sure your document is properly encoded (both Windows-1252 and UTF-8 would do here) and the encoding is properly declared.