Can't get any Javascript to work in SL2 course
Jul 29, 2015
Hi everyone,
I may have gotten a little big for my britches and tried to add a few Javascript commands to my course without actually knowing anything about Javascript. And now they don't work.
Background:
I found and used this really excellent guide on how to Add a Completion Certificate to a Storyline file to add three Javascript commands to my course:
- pull user name from LMS to display on a completion certificate
- generate date of completion of course to display on a completion certificate
- print certificate when clicking on on-screen button
None of them work. Not when I publish to the LMS. Not when I publish locally and view in Chrome or IE. Even the print command which has less characters than my name!
Is there a box that I may have missed clicking on? Or something that changed from SL1 (which the truly wonderful guide was written for) and SL2 (which I created the course in)? Do I need to turn around three times and spit? I'll do it!
Thanks in advance for any guidance!!
16 Replies
Hi, Elizabeth -- Welcome to the community! :)
You may already be aware of this, but Articulate does not offer support for JavaScript coding, however, it may be helpful to take a look at this document on JavaScript Best Practices. Hopefully, some of our JS experts in the community can chime in with suggestions!
This post was removed by the author
Thanks, Christie! I reviewed the Best Practices, but couldn't find any help for my issue. I've attached a file that shows what I'm trying to do.
Thank you!!
Hi, Elizabeth -- Thanks for reviewing the JS Best Practices info, and for sharing your file. I am hopeful that one of the amazing JS gurus here in the forum will be able to nail down where the issues are occurring and get you back in business!
I saw two issues.
1. In your date script you reference a Storyline variable 'SystemDate' that was not defined. I assume you meant this to be 'varCompleteDate'
2. There was a line break in one other script line (the one that defines the months array).
With these two items fixed, it should work.
Thanks so much for the suggestions, Michael! Please give his advice a shot and let us know if you are all set, or still need additional assistance, Elizabeth. :)
Hi Michael,
Thank you!! The line break seems to have fixed everything except for the Print command.
I can now get the print screen to load, but it shows a blank page in preview, not the certificate. Has anyone run into this before? Could it be that my browser is blocking the content somehow?
Out LMS (IBM Kenexa) will allow users to print a report of their scores and date of completion, but it looks terribly, so I'd love to avoid it!
Thank you again for the review!
Hi Elizabeth,
You won't be able to test the Javascript elements in preview - you'll need to publish and place within the intended environment as described here. If you need to hold off on placing in your LMS - you could use SCORM Cloud as a testing site.
Michael's troubleshooting fixed most of the problems with the exception of:
1. Date generation - the date being generated is a year off, 2016 instead of 2015.
2. Print command - the print dialog box comes up, but it shows a blank page instead of the content on the screen.
Thanks all for any insight!
Hi Elizabeth,
Did you try testing it in the published output within the intended environment as I mentioned above?
Hm, this is odd. When I publish your project, I a) see the correct date and b) can print. See attached screenshot.
I, too, have had nothing but difficulty with Javascript in Storyline. I've followed many eLearning tutorials verbatim and published to the LMS and to CD. I've never been able to get any Javascript to work in Storyline. I do have a little experience with coding & scripting, and understand the concepts and practices, but I'm not well versed in Javascript. Is there an obscure setup option or publishing setting that everyone seems to know but me?
Hi S.,
I'm not equipped to assist with the actual code of Javascript - but when you're publishing to the LMS are you also uploading to test there or just testing locally? You'll want to test within the intended environment as detailed here.
Hi S.,
I was never able to get the Print command to work correctly, which may have something to do with my browser settings or network configuration. After Michael fixed my code above, that corrected the name retrieval and date generation, though.
Good luck, and I wish I had a magic word to offer you!
Thanks for responding-- and I apologize for diverting the thread. I'm going to see if I can get your certificate script to work and I'll see if I have the same issue with printing.
You might want to post your .story file here so that a community member can have a closer look at your JS issues.
Hi S,
I'd agree with Michael that it is likely best if you can let the community take a look so that they're able to see if there is just something off in the code set up.
This discussion is closed. You can start a new discussion or contact Articulate Support.