Custom JavaScript not Recognizing Object Names

ccowan-3574
Community Member Posts: 2 ☆ Roadie ☆
Hello Rockstars,
I'm using Lectora Online and am trying to implement custom javascript. When I reference an object using getDisplayDocument().getElementById("[objectName]") in the Run Custom JavaScript field it returns an error that the referenced object is 'null'. This happens whether I use the name I have given it or use the HTML name assigned by Lectora.
I have managed to get text objects to work, but only by accessing the HTML and manually adding id="[objectName]" as an attribute to the
I'm using Lectora Online and am trying to implement custom javascript. When I reference an object using getDisplayDocument().getElementById("[objectName]") in the Run Custom JavaScript field it returns an error that the referenced object is 'null'. This happens whether I use the name I have given it or use the HTML name assigned by Lectora.
I have managed to get text objects to work, but only by accessing the HTML and manually adding id="[objectName]" as an attribute to the
tag. Am I missing something simple here?
Tagged:
Comments
-
wheels Florida USACommunity Member, Administrator, Moderator, Rockstar Manager Posts: 666 eLearning ROCKSTAR Admin TeamYou can setup a JavaScript variable that points to the Lectora object.
For example:
Button GREEN
(add an action to the button)
On Page Show -> Run JavaScript -> getDisplayWindow().greenButton = %HTMLNAME%;
To show the button from JavaScript:
getDisplayWindow().greenButton.actionShow();
To get to the Lectora object DOM structure reference the object's div element:
console.log(getDisplayWindow().greenButton.div.id);
https://rockstars.elearningbrothers.com/discussion/comment/454293#Comment_454293
-
Cainam - Thanks for your reply. Yes, that was one of the ways I tried to access the items without any luck. I really appreciate your response, though.
Wheels - That helps! I gave your example a try and it worked. So going forward I'll follow that format - setting up a variable for objects that I want to work with. Thank you very much!!
Categories
- 35.9K 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
- 324 CenarioVR®
- 191 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