Javascript split() breaking my code

Mar 03, 2016



Hello all, So I have this code and all is good. I am collecting Notes form the course then on click I want to print them out. Well they come out in a single line like (XXXXXXXXXX DDDDDDDDDDD SSSSSSS) for each section. What I want to do is use the split() function to make 3 in this case number if lines.

Whenever I place the split function in the code and press the btn nothing happens.
Below is the good code

var player = GetPlayer();

//var course = player.GetVar("courseName");
var notes1 = player.GetVar("TE_CCE_Overview_Notes");
var notes2 = player.GetVar("TE_Market_Drivers_Notes");
var notes3 = player.GetVar("TE_Benefits_Notes");
var notes4 = player.GetVar("TE_Ideal_Customer_Notes");
var FontSizeHead = "18px";
var FontSizeBody = "12px";;
newdocument=newwindow.document; d = new Date();
newdocument.write('<style>body{padding:20px;font-family:arial,sans-serif}</style>'+' <span style="font-size:"'+FontSizeHead+';">Notes - '+(d.getMonth() + 1)+'/'+d.getDate()+'/'+d.getFullYear()+'</span>'+' <br><br>'+' <span style="font-size:'+FontSizeBody+'"><strong>TE CCE Overview Notes:</strong><br />'+ notes1 +'</span>'+' <br><br>'+' <span style="font-size:'+FontSizeBody+'"><strong>TE Market Drivers Notes:</strong><br />'+ notes2 +'</span>'+' <br><br>'+' <span style="font-size:'+FontSizeBody+'"><strong>TE Benefits Notes:</strong><br />'+ notes3 +'</span>'+' <br><br>'+' <span style="font-size:'+FontSizeBody+'"><strong>TE Ideal Customer Notes:</strong><br />'+ notes4 +'</span>');

Now after var FontSizeBody = "12px"; I add

var N1 = split(notes1, \/n);

Then replace the notes1 var down in the body of the new html with N1 the wheels come off and nothing happens.

Any ideas/suggestions?





3 Replies
Bobby P

Thank you for your response but I seem to still be missing something. Can you please help?

var notes1 = player.GetVar("TE_CCE_Overview_Notes");
var N1 = notes1.split("\n");
//var N1 = notes1.split(/[a-z]+$/gm);
//var N1 = notes1.replace(/ \n /,"<br/>");
//var N1 = notes1.replace(/ \f /,"<br/>");
//var N1 = notes1.replace(/ \r /,"<br/>");

for (i = 0; i < N1.length; i++) {
    N1String += N1[i] + "<br>";

//var N1String = "";
//for (i = 0; i < N1.length; i++) {
//    N1String += N1[i] + "<br>";
// }

I will type into my textentry box 3 lines

Fred was here
Tom was here

Bobby was here

When I check it comes back as one string.  I am unable to detect the end of the line so I can insert a <br /> tag

Thanks for any help



This discussion is closed. You can start a new discussion or contact Articulate Support.