Pass URL

I have a url test.com?userID=1111&key=111, which launch the lectora lesson

undefined

I neeed to be ABLE TO pass userID and the key to lectora lesson

Discussion (18)

Thank you. I have followed the instruction and I got this far.

function getParameterByName(name, url) {

if (!url) url = window.location.href;

name = name.replace(/[\[\]]/g, '\\$undefined

if (!results[2]) return '';

return decodeURIComponent(results[2].replace(/\+/g, ' '));

}

var userkey1 = getParameterByName('userKey');

var sessionUnitKey1 = getParameterByName('sessionUnitKey');

alert(userkey1 );

I have created 2 variables in Lectora userkey and sessionunitkey

The problem is to set the variable for Lectora .

undefined

when I do this I get an error message

Varuserkey.set( userkey1 );

Varsessionunitkey.set( sessionunitkey1);

You can add a Run JavaScript action and get the query string parameters using JavaScript.

See here for required JavaScript:

https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript

Then you can create user variables in Lectora, MyUserId and MyKey.

In your JavaScript you can set those variables using the set method:

(variable JavaScript names can be found in the variable manager)

VarMyUserId.set( idParam );

VarMyKey.set( keyParam );

Then you will have those values available in Lectora variables to use in your course.

The error message that I am getting is : ReferenceError Varuserkey is not defined

You have to use the variables in a Lectora action. Otherwise Lectora believes they aren't needed and doesn't initialize them. If you want to use the variable later on the same page just create this action first. You can also add a group on title level with 1 action "Reset all variables". This action uses all variables at once, just don't Run this action group if you don't want to reset the variables.

Add a group on title level. Add one action to the group "Reset all variables".

This should solve the "Varuserkey is not defined" issue.

I want to store the variable in lectora so I can pass it later when I submit the test to a processing page. So I got the javascript to work. Now in Lectora what do I need to do

On the title level I am also setting running my JS file . What should happens first. And can I create a group and reset variables first and then run the JS or reverse the order in the same group?

undefined

My variables does not get set. have attached my awt file I do not know what I am doing wrong. Please advise

undefined

I

will try this

The awt is not in the zip.

It seems you've put the "function getParameterByName(name, url) " into a "Run javascript" action. That's not advisable because the action is turned into a function again. It's better to put it into an HTML Extension (Insert undefined

The action in the group is not meant to be executed, it only exists to make Lectora initialize all variables, i.e. sequence is not relevant. Just put it there, your JS won't be influenced.

Still does not work . Attached should have awt file

There are two decisive typos in your code:

"Varuserkey is not defined", because in Lectora there is no variable called "userkey". The name of your variable is "userKey".

When using the function you need to pass the correct values:

You wrote your url looks like this:

test.com?userID=1111&key=111

To "getParameterByName(name,url)" you need to pass the name of the parameter, which is "key" not "userKey". The other parameters name is "userID", exactly like it is spelled in the URL.

I am trying to execute that code now. I does not always work. The JS does not seems to trigger on the page show. I am puzzled . Please help

Are there any javascript errors in the console? I'm not sure why it would work sometimes but not always ...

I tested the code above and it seemed to work.

What I found If I add the content page before. So it will be the first page then nothing get stored. Is there a way to only stored upon arrival basically on the first page and then carry through the entire lessons. My lesson will be 100+ pages plus a quiz

You can add a condition to check whether the variable already contains a userKey, i.e. check whether it contains a value that is not the initial value of the variable, e.g.

Run Javascript Only if "userKey" Not equal to "0".

@wheels and @timk Thanks to you both for this discussion. It's helped me in similar situation with dealing with local servers.