Accessing variables in an external javascript file with Lectora
smcculley1282
Community Member Posts: 14 ☆ Roadie ☆
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
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
Comments
-
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". -
Categories
- 35.8K All Categories
- 108 ✫ 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
- 5 The Training Arcade®
- 5 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