Explore the community Forums Lectora Lectora Questions & Answers Set Question variable via javascript

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #296342 Score: 0
    Profile photo of Marco Meissner
    Marco Meissner
    Member
    beginner
    intermediate
    Group Member
    curious george
    contributor
    wise owl
    4 pts
    @marco.meissner

    Hello,

    I have a question about setting a question-variable in Lectora from within a javascript function.

    To make it easier I will upload a small testfile. OK – what is my problem:

    I have one  numeric question on a page. The user can enter the answer and click on check; the feedback works… everything is fine.

    But now I want to use a javascript, which will change the question-variable to the correct answer. But this javascript only works if the user have not filled in any value manually. If there is a value in the inputfield and the answer has been checked for the first time, then the question cannot be checked once again; nothings happens if the user clicks on the check-button.

    I have no idea how to modify the javascript that the question can be checked twice – is there anybody out there who can give me a hint?

    Thanks,

    Marco

     

     

    #296364 Score: 3
    Profile photo of Sergey Snegirev
    Sergey Snegirev
    Member
    contributor
    intermediate
    advanced
    friend finder
    lab member
    junior moderator
    advocate
    LUC16
    LUC16 Attendee
    wise owl
    337 pts
    @ssneg

    Lectora does not allow you to process a question more than once unless its value has changed. It detects the value change through the “onchange” and “onkeyup” listeners on the input field. So it marks the question as “processed” right after you first click on ‘Absenden’ and will ignore any further presses on that button. Lectora marks the question as “unprocessed” as soon as you type anything in the field (and thereby trigger onchange/onkeyup). Just setting the text input field to another value does not trigger any of those events. This is why your script won’t work.

    So if you want to manipulate the question through script, you have to add one extra line to your correctanswer() function to make sure the question can be processed again:

    function correctanswer() {
    qu40.hasBeenProcessed = false; //qu40 is your question's unique id in Lectora
    VarFrage_0001.set('1');
    document.getElementById('entry43id').value='1' ;
    }
    This post has received 3 votes up.
    #296391 Score: 0
    Profile photo of Marco Meissner
    Marco Meissner
    Member
    beginner
    intermediate
    Group Member
    curious george
    contributor
    wise owl
    4 pts
    @marco.meissner

    Perfect  – that’s it!

    Many thanks,

    Marco

     

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

You must be logged in to reply to this topic.