Retain line breaks in text variable when exporting via Javascript

My goal is to have participants create three different Action Plans during the course, then at the end of the course display all three action plans side by side and give participants an option to email the action plans to themselves and cc: their manager.  After much wrangling, I've figured out the variables and javascript to make all this happen exactly how I want except for one tiny detail.

When the participants complete each action plans, I would like them to write them in a list format, like so:

first action

second action

third action

When the action plan is displayed at the end of the course, it retains the line breaks properly and displays it exactly as the participant typed it in. However, when I use javascript to grab the variable for the action plan and place it in the body of the email using mailto:, it displays like so:

first actionsecond actionthird action

Is there any way to preserve the line breaks from the text entry box when it's exported via javascript?

Thanks!

Here's the script I'm using and I'll attach the story file I've been testing with.

var player=GetPlayer();

var name=player.GetVar("UserName");

var topic_one=player.GetVar("TopicOneActions");

var topic_two=player.GetVar("TopicTwoActions");

var topic_three=player.GetVar("TopicThreeActions");

var email=player.GetVar("UserEmail");

var cc=player.GetVar("ManagerEmail");

var subject="Action Plan for "+name;

var body="Topic One: "+topic_one+"%0D%0ATopic Two: "+topic_two+"%0D%0ATopic Three: "+topic_three;

var link='mailto:'+email+

'?subject='+subject+

'&cc='+cc+

'&body='+body;

window.open(link);

14 Replies
Doug Brown

Hi Tracy

You need to replace all the hidden new line characters, so after this line

var body="Topic One: "+topic_one+"%0D%0ATopic Two: "+topic_two+"%0D%0ATopic Three: "+topic_three;

INSERT

body = body.replace(/\r\n?/g, '%0D%0A');

This will search for all new lines \r\n and replace them with the correct characters

Updated file attached

Doug

John Beaudoin

Hi folks...

I am attempting to do the exact same thing here...

Im using Doug's script to capture some notes that the learners types in as they proceed through the course....

I downloaded Doug's .story file , published it as SCORM 1.2 and ran it locally. it worked perfectly. When I clicked submit, my Outlook client launched and the email fields were all filled in as designed..

I used that same script (just swapped out for my variable names) and published for SCORM, and the Outlook Client will not launch. So confused!!!!! 

John Beaudoin

OOps. I meant to send this along...here is my modified code. I took out CC line as I hadnt a need for that..

Basically, Unit1Notes, Unit2Notes, and Unit3Notes are text entry fields that allow the learner to enter in notes as they proceed through course... learnermail variable is the learner's email that they entered earlier in the course...

var player=GetPlayer();

var notes1=player.GetVar("Unit1Notes");

//notes1 = notes1.replace(/\r\n?/g, '%0D%0A');

var notes2=player.GetVar("Unit2Notes");

var notes3=player.GetVar("Unit3Notes");

var email=player.GetVar("learneremail");

var subject="Course Notes for "+learneremail;

var body="Unit 1 Notes: "+notes1+"%0D%0AUnit 2 Notes: "+notes2+"%0D%0AUnit 3 Notes: "+notes3;

//NEW LINE

body = body.replace(/\r\n?/g, '%0D%0A');

var link='mailto:'+email+

'?subject='+subject+

'&body='+body;

window.open(link);

Andy Houghton

Hi

I'm working on a project which has a notepad - the users can add text to it as they go through a module. I've used this: body = body.replace(/\r\n?/g, '%0D%0A'); to keep the line breaks intact when sending the text from the notepad to email.

Does anyone know if there's any equivalent that works when printing?

Thanks

Andy

Daniel Bolia

Hello,

I looked at Doug Brown's storyline file, javascript_2btest_2b-_2bgeneric_doug.story, to test and adapt for a project I'm working on. I noticed that the published file works perfectly in IE but not Firefox. I'm hoping that others in the community may have a solution for this problem.

Thank you!