Formatting text entry gathered for email body

Sep 17, 2022

I have set up a journal that at the end of the course the user can email to themselves. Is there any way in the javascript to add some formatting? I have tried a couple of things but it just breaks the code.

Thanks,
Gerry

7 Replies
Gerry Babuin

Thanks Stefan

Here is the code:

var player = GetPlayer();
var email = 'Email';
var ans1 = player.GetVar('TextEntry_Intro');
var ans2 = player.GetVar('TextEntry_GrandIllusions');
var ans3 = player.GetVar('TextEntry_Master');
var subject = 'My Happiness Journal';
var emailBody = 'Be Happy Journaling' + '\n' + 'Introduction Journaling: ' + ans1 + '\n\n' + 'Grand Illusion Journaling: ' + ans2 + '\n\n' + 'Master Journaling: ' + ans3;
var mailto_link = 'mailto:' + email + '?subject=' + subject + '&body=' + encodeURIComponent(emailBody);
win = window.open(mailto_link, 'emailWin');

Stefan Gottfried

I tried to alter your code a bit it gets the empty lines done in my test-file:

var player = GetPlayer();
var email = 'Email';
var ans1 = player.GetVar('TextEntry_Intro');
var ans2 = player.GetVar('TextEntry_GrandIllusions');
var ans3 = player.GetVar('TextEntry_Master');
var subject = 'My Happiness Journal';
var emailBody = 'Be Happy Journaling' + '%0A' + '%0A' +'Introduction Journaling: ' + ans1 + '%0A' + '%0A' + 'Grand Illusion Journaling: ' + ans2 + '%0A' + '%0A' + 'Master Journaling: ' + ans3;
var mailto_link = `mailto:${email}?subject=${subject}&body=${emailBody}`;
window.location.href = mailto_link;