Set Question variable via javascript

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
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
-
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' ; }
-
Categories
- 35.8K All Categories
- 109 ✫ Announcements
- 33.1K Lectora®
- 31.1K Lectora Discussions
- 28.9K Lectora Desktop
- 2K Lectora Online
- 2K Lectora Feature Requests
- 71 Lectora User Groups
- 36 Lectora Accessibility User Group (LAUG)
- 22 ELB Learning Content
- 22 ELB Learning Content Discussions
- 321 CenarioVR®
- 188 CenarioVR Discussions
- 133 CenarioVR Feature Requests
- 41 Rockstar Learning Platform®
- 38 Rockstar Learning Platform Discussions
- 108 CourseMill®
- 108 CourseMill Discussions
- 47 ReviewLink®
- 47 ReviewLink Discussions
- 7 The Training Arcade®
- 7 The Training Arcade Discussions
- 934 All Things eLearning
- 36 eLearning Development
- 546 Learning Management System (LMS) Integration
- 332 Web Accessibility
- 1.2K ♪ The Green Room
- 9 Additional Learning Products