Explore the community Forums Lectora Lectora Questions & Answers Another JS scoping problem Reply To: Another JS scoping problem

#365724 Score: 0
Profile photo of Math Notermans
Math Notermans
Member
contributor
intermediate
advanced
friend finder
junior moderator
advocate
LUC16 Attendee
LUC16
wise owl
curious george
129 pts
@mnotermans5114

Might be good to add a sample. Much easier to see whats happening and add any possible fix for it. I can think of several solutions. Basically you need a container at root level of the title that will hold the variables. I do think the use of Javascript on Lectora objects delays the script from running, if you use the Javascript at the core HTML level, eg. triggering a JS on loading the HTML will fix this.

JavaScript will run while your page is being rendered. A common mistake is to execute a script that tries to access an element further down the page. This fails because the element isn’t there when the script runs. Offcourse putting a Javascript on a Lectora object ensures its available, but also that can be late in the process.

Both the jQuery option $(document).ready() or the windows default ‘window.onload’ ensure scripts load at the proper time. I mostly use $(document).ready().

I do think using this approach would remove the delay. And using the javascript in the root of the title in stead of on a specific object might solve the page issue. Easiest would be a sample to test and show however 😉