Completing a URL with a variable


I'm working on a project in which I would like users to type in their employee ID to access a personalized report via URL. Let's say my employee ID is 1234 and my URL is something like

I would like the user to enter their employee ID at the beginning of the course, then use that variable to fill in the "1234" portion of the URL above.

I'm a javascript novice, but I I'm pretty sure it can be done. It seems like it is possible using the player.GetVar method mentioned in the JavaScript Best Practices. Any ideas?


2 Replies
Matt Galbraith

I just visited with a colleague who answered my question.

Originally, I was using a text variable named "UserID" in Storyline to capture the employee ID and my code looked like this:

var player = GetPlayer ();"" + player.GetVar (UserID)+ ".pdf");

This wasn't working because JavaScript can only insert JavaScript variables into the line.  So I needed to use the Storyline variable to define the JavaScript variable (which I named "number"), which looks like this:

var player = GetPlayer();

var number = player.GetVar ("UserID");

As you may have noticed, I also forgot to include the quotation marks around my Storyline variable in the original code. Now that I have created a JavaScript variable, I can insert it in the line.  The full code looks like this:

var player = GetPlayer();

var number = player.GetVar ("UserID");"" +  number + ".pdf");

This worked for me. I hope this helps someone else.