Javascript split() breaking my code
Mar 03, 2016
By
Bobby P
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";
newwindow=window.open();
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?
Thanks
B
3 Replies
Hi Bobby,
I think you need to call split function like this - one is string & other one is regex
var N1 = notes1.split("\n");
or
var N1 = notes1.split(/\n/);
Hope it helps.
Thank you for your response but I seem to still be missing something. Can you please help?
I will type into my textentry box 3 lines
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
B
Hi Bobby,
Could you please share your story file? It's easier to debug that way.
Thanks.
This discussion is closed. You can start a new discussion or contact Articulate Support.