Returning a multiple-line text string

Okay, using a JS function to create text. In a nutshell, the string tells you what happened to a number of characters under your control. To make it readable, I want it to show a line per character.

So if I have something like this in a function...

var reStr;

retStr = "text block one";
retStr += "text block two";

return (retStr);

...and I want retStr, when printed in squiffy using the string returned, to say...

text block one
text block two

with a carriage return between the output lines.

So how does one insert a new-line character into a text string in JS that returns correctly in squiffy?

If you want to insert a newline, you can use \n wiithin double quotes.

However, if you're just going to display this string to the user, you need to be outputting HTML (as the browser treats all whitespace, including newlines) as a single space).

So something like a line break:

retStr = "text block one<br/>";
retStr += "text block two";

or define your text as belonging to two paragraphs:

retStr = "<p>text block one</p>";
retStr += "<p>text block two</p>";

Nailed it. Thanks! I like the "br" solution and will go with that. Now, after breakfast, I can jump back into coding!

This topic is now closed. Topics are closed after 60 days of inactivity.