Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #441017 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

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

     

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

    #441136 Score: 0
    Profile photo of Joe Wieloch
    Joe Wieloch
    Moderator
    beginner
    intermediate
    friend finder
    contributor
    LUC16 Attendee
    verified member
    wise owl
    LUC17 Attendee
    advanced
    picture perfect
    55 pts
    @wheels

    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.

    #441152 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

    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, ‘\\$&’);
    var regex = new RegExp(‘[?&]’ + name + ‘(=([^&#]*)|&|#|$)’),
    results = regex.exec(url);
    if (!results) return null;
    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 .

     

    when I do this I get an error message

    Varuserkey.set( userkey1 );

    Varsessionunitkey.set( sessionunitkey1);

    #441155 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

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

    #441172 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    333 pts
    @timk

    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.

    #441183 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

    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

    #441212 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    333 pts
    @timk

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

    This should solve the “Varuserkey is not defined” issue.

    #441232 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

    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?

     

    #441234 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    333 pts
    @timk

    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.

    #441236 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

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

    Attachments:
    1. Unit-2-Quiz.zip
    #441247 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    333 pts
    @timk

    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 > Add Web Object > HTML Extension), change the type to “Header Scripting”. Click Edit, enter the function code and remove it from the action, i.e. only the function, leave the rest.

     

    #441251 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

     

    I

    will try this

    #441315 Score: 0
    Profile photo of TomTom
    TomTom
    Member
    beginner
    intermediate
    wise owl
    friend finder
    curious george
    contributor
    @TomTom

    Still does not work . Attached should have awt file

    Attachments:
    1. Unit-2-Quiz-1.zip
    #441319 Score: 0
    Profile photo of Tim K
    Tim K
    Member
    contributor
    beginner
    intermediate
    advanced
    friend finder
    junior moderator
    advocate
    wise owl
    curious george
    Group Member
    333 pts
    @timk

    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.

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.