Custom JavaScript not Recognizing Object Names

ccowan-3574
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

tag. Am I missing something simple here?

Comments

  • cainam
    cainam Community Member Posts: 350 ♦ Idol ♦
    (I don't personally use this much, so pardon me if I'm off-base) - are you accessing the items like this, or using another method?

    - Adam Cain
  • wheels
    wheels Community Member, Administrator, Moderator, Rockstar Manager Posts: 569 eLearning ROCKSTAR Admin Team
    You 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
  • ccowan-3574
    ccowan-3574 Community Member Posts: 2 ☆ Roadie ☆
    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!!
Sign In or Register to comment.

So You Wanna Be An eLearning ROCKSTAR?

We're all fans of eLearning here! Want to become an eLearning ROCKSTAR? Just click on one of the buttons below to start your rocking journey!