Set Question variable via javascript

marco-meissner
marco-meissner Community Member Posts: 17
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

 

 

Comments

  • ssneg
    ssneg Community Member Posts: 1,466 ☆ Roadie ☆
    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' ;
    }
  • marco-meissner
    marco-meissner Community Member Posts: 17
    Perfect  - that's it!

    Many thanks,

    Marco