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

tag. Am I missing something simple here?


  • cainam
    cainam Community Member Posts: 365 ♦ 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 Florida USACommunity Member, Administrator, Moderator, Rockstar Manager Posts: 666 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:

    To get to the Lectora object DOM structure reference the object's div element:
  • 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!!