Trouble with Java: Printing Multi-line text variables

I have been hunting for awhile, but I can't seem to find the answer I need to produce the results I am looking for and I know it is likely something simple.

What I have is a notes text variable that a user can write down thoughts and they are going to print it at the end, exporting it to a custom branded html page using a java print function. A user might type in the following, across multiple lines:

Some Text

Some more text

Even more text

When it exports for print, it exports as such:

Some TextSome more textEven more text

What code am I missing to provide the line breaks that were entered by the user when typing into the text field on export?

What I have is the following for the button:

var player = GetPlayer();

var header = "Notes~~"
var body =(player.GetVar("Notes1")).replace(/\r\n?/g, '%0D%0A');
var url = ("print.html?=" + header + body);

window.open(url,"_blank","width=800,height=600,menubar=yes,scrollbars=yes");

I attached the print.html file for review as well. 

 

3 Replies
Josh Yavelberg

Addendum:

I did try the following. I entered into the course:

Some Text</br>

Some more text</br>

Even more text</br>

And I received what I was looking for in the print.html:

Some Text

Some more text

Even more text

On the export to print. The trouble here is that an average user is not going to write in a response to a text variable using HTML code. 

Josh Yavelberg

This is a really useful way to print custom notes. So I thought I would answer my own post (after much hair pulling). It seems I needed to provide the following when assigning a multi-line input variable for export.

var player = GetPlayer();

var header = "Notes~~"
var agr = player.GetVar("Notes1");
var body = agr.replace(/\n/gi, "<br />");
var url = ("print.html?=" + header + body);

window.open(url,"_blank","width=800,height=600,menubar=yes,scrollbars=yes");

The trick is to pull the variable from articulate, then create a new variable before exporting it for display in an HTML page. This is really good to know if you are trying to export any of your long-answer survey type responses.

*UPDATE: While this worked locally, when I uploaded it to the LMS, the line breaks again are removed... So I am still looking for a universal solution here.