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

#414585 Score: 0
Profile photo of Tim K
Tim K
friend finder
junior moderator
wise owl
curious george
Group Member
354 pts

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()


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”.