Execute Javascript Trigger

May 14, 2014

I've added 4 buttons in Storyline to show some examples of JavaScript in e-Learning.

Each button has a trigger to execute the Javascript code (which I got directly from w3schools).

They are labeled: 

  1. Now
  2. Print
  3. Browser
  4. Hello

To execute these corresponding JavaScript codes (onClick): 

  1. Display current date and time
  2. Print the current page
  3. Displayer user's browser version
  4. Display a Hello message after 3 seconds

Codes are provided in attachment.

I published to HTML and viewed the page but none of the JavaScript is executing.

So I'm reaching out for help... is there a step I'm missing; does this need to be loaded to an LMS to function, or something else? 

I've also noticed that my sample to launch EMail when clicking a button doesn't work either. 

Thanks for any tips you can provide,

christine 

8 Replies
Nancy Woinoski

Hi Christine, you might want to take a look at these basic JavaScript examples to get a better idea of how the JS code should be structured in Storyline and how to use the GetPlayer(), SetVar() and GetVar() JavaScript methods that are supported in Storyline.  http://www.articulate.com/support/storyline/javascript-best-practices-and-examples

Marco Faust

YES to what Christine said.

You will notice when you look at it that when you put the Javascript into the triggers you are not supposed to put all that stuff in there like headers etc.  Out of the code you have, all you need is actual Javascript commands.  

For example: that first one for date.  You are going to need something that looks like this:

var player = GetPlayer();

player.SetVar("sDate",Date());

BUT, you are going to need to establish a variable in Storyline called sDate and it is going to give you a date that you might not expect.  It gives a long verbose date that includes timezone UTC etc.

You'll need to look up other Javascript for formatting.

CHRISTINE OMALLEY

Michael,

This is exactly what I would like to include in my sample...

I've tried to follow your lead and remove the extra coding from the scripts but I think that I'm still missing something.

For example, I changed the code for the first button to execute this code: 

function myFunction() {

    document.getElementById("demo").innerHTML = Date();

}

Can you guide me please, or share the modified code you used? 
I have not included a Reference. Do I need to do that? 
Thank you!
Also - TO EVERYONE WHO REPLIED... 
Thank you so much, from top to bottom - your suggestions are very helpful. My JavaScript is definitely rusty and what I REALLY love about this 'predicament' I'm in is that it inspired me to sharpen those sklls. 
Michael Hinze

christine omalley said:

Michael,

This is exactly what I would like to include in my sample...

I've tried to follow your lead and remove the extra coding from the scripts but I think that I'm still missing something.

For example, I changed the code for the first button to execute this code: 

function myFunction() {

    document.getElementById("demo").innerHTML = Date();

}

Can you guide me please, or share the modified code you used? 
I have not included a Reference. Do I need to do that? 
Thank you!
Also - TO EVERYONE WHO REPLIED... 
Thank you so much, from top to bottom - your suggestions are very helpful. My JavaScript is definitely rusty and what I REALLY love about this 'predicament' I'm in is that it inspired me to sharpen those sklls. 
Hi Christine, see attached my sample file. Hope that helps.

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