Special character truncating text in variable

We have a story file that allows learners to take notes in a couple of fields and then email those notes to themselves. We just realized that if the learners include an & in their notes, the notes content is truncated at that point. So a learner types this in the field "These are my notes about apples & oranges." - the email they get will only say "These are my notes about apples"

We are using a JavaScript trigger with the following code:

var player = GetPlayer();

var useremail=player.GetVar("Emailtextentry1");

var subject="Emergency and Urgent Care Course";

var exercisenotes1=player.GetVar("Thoughts1");
var usernotes=player.GetVar("notes");

var body="Activity Notes: "+exercisenotes1+"%0D%0AFinal Notes: "+usernotes;

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

var link='mailto: '+useremail+
'?subject='+subject+
'&body='+body;

window.open(link);

Is there a way to make JavaScript see the & (or any special character - that may not be the only one) as a text character and not a code character?

3 Replies
Laura Winzen

COOL!!

I'm not seeing how I incorporate this into my existing code though. I wish the example showed where the vars go.

I added these lines to my code but it did not work. Can you see what I've done wrong?

var uri1 = "https://w3schools.com/my test.asp?exercisenotes1=ståle&car=saab";

var res = encodeURIComponent(uri1);

var uri2 = "https://w3schools.com/my test.asp?usernotes=ståle&car=saab";

var res = encodeURIComponent(uri2);

Michael Anderson

To use your subject variable as an example, I think you would just have lines like this

var subject="Emergency and Urgent Care Course";
subject = encodeURIComponent(subject);

So you defined your variable text in the first line, then the next line runs it through the encoding. I didn't have time to test this, so please tell me if it doesn't work.