Explore the community Forums Lectora Lectora Questions & Answers Accessing variables in an external javascript file with Lectora

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #414568 Score: 0
    Profile photo of Shawn McCulley
    Shawn McCulley
    Member
    beginner
    intermediate
    friend finder
    curious george
    picture perfect
    wise owl
    contributor
    @smcculley1282

    Hello.

    I am creating an assessment quiz that will eventually have 9 variations which is why all the text for the questions and answers is in one javascript file. I am able to access the text for the question and answers in the javascript file just fine. The question I have is on the very last page of the assessment, “Feedback.” We want to be able to put the text of each question along with other information into a table. On the first line of the table, I have the Lectora variable VAR(mytest), which right now returns “0.” What I want to do here is to the put the value (or text) of the variable “Q1” (in the external javascript file AssessmentQText.js, line 26) into the VAR(mytest) variable and have that text appear in row 1, cell 2 of the table. Is this possible? If so, what is the correct syntax to make this work?

    Any help with this is much appreciated. My Lectora project file is attached.

    Thanks.

    -Shawn

    #414585 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
    315 pts
    @timk

    Inline variable replacement with “VAR(mytest)” has been designed to insert the page name into a textfield so fast, a user cannot see the default text of the field. So this is what happens first when the page is loaded and it happens only once.

    All actions to modify that variable are executed later, i.e. the action to set the variable to “8” is working but it happens after the variable has been inserted into the textfield, when its value is still equal to “0”. It should work if you modify the variable on a previous page.

    The code to set a Lectora variable with javascript is: Varvariablename.set(“Value”);

    For testing you can add it to your function updateQuestion1()

    Varmytest.set(Q1);

    Be aware that you need a Lectora action that uses the variable “mytest” on the question page. Otherwise it won’t exist. The easiest way to achieve it is to add a Group on Chapter level with one action to “Reset all variables”.

    #414699 Score: 0
    Profile photo of Shawn McCulley
    Shawn McCulley
    Member
    beginner
    intermediate
    friend finder
    curious george
    picture perfect
    wise owl
    contributor
    @smcculley1282

    Hi Tim. Thank you for your quick rely. Your answer worked and I am able to correctly access the variables in my javascript file.

    -Shawn

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

You must be logged in to reply to this topic.