Javascript not working

May 28, 2013

I have some javascrpt set up to send a variable externally but it isn't actually sending.

var name = player.GetVar("Name")

document.getElementById("name").setAttribute("value", "name");

I set this in an execute java script when a slide starts. I have a variable %Name%. 

Any ideas?

4 Replies
Dave Cox

It is kind of hard to know what you are doing with what you've posted here.

"var name = player.GetVar("Name"); " will work fine if you have already set the statement "var player = GetPlayer();

Either way, this function returns the variable "Name" from the player. Have you created the variable Name in your project in the variables panel?

The statement "document.getElementById("score").setAttribute("value", "score");" get an html element with the ID of "score", and sets its attribute value to the value of the variable of the variable "score". This would be a variable in your html code, not in the player. Is that what you wanted? (Id of score and a variable named score are not the same). If you wanted to set the value of "score" in the player, you need to use SetPlayer();

In Storyline, %TXT% displays the storyline variable TXT. Is this variable set in the variables panel?

Try adding a statement to produce output at the console. This way you can see what is happening as your code runs. For example, after you run var name = "player.GetVar("Name");" run the statement 'console.log("Name " + Name);' This will print the Name variable to the console.

When you run your project, Press F12 to open the debug window, and select the console tab. The you can see the messages that are sent to the console.

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