Explore the community Forums Lectora Lectora Questions & Answers JavaScript: Getting Object Names

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #283381 Score: 0
    Profile photo of appdevpub
    friend finder


    I am pretty new to Publisher but I have two quick yet important questions:

    1. Can I use JavaScript, attached to a Page, to get all the names of objects on a page? All the text fields, etc. Maybe there’s a way to use the DOM to loop through a Page object?

    2. Also, I tried using Run JavaScript on Show event of a Page to run
    document.getElementByID(‘HTML_Object_Name’).write(‘hello, world’);

    Is this the correct approach to accessing Lectora objects in html?


    #287078 Score: 1
    Profile photo of Ben Pitman
    Ben Pitman
    4 pts

    Yes you can. I have done it a lot. The code is NOT easy. If you send me an email, I will be glad to reply with the code.

    Complex JavaScript in Run JavaScipt action is tricky. You need to use a lot of { } even when there is only one stmt after an IF, especially if there is an Else. Best to put Functions in HTML obj or an attached JS file.

    This post has received 1 vote up.
    #299889 Score: 0
    Profile photo of Rob Ball
    Rob Ball

    Ben, I am sending you a PM, I hope you are still watching this forum,

    #299905 Score: 1
    Profile photo of Darrel Somoza
    Darrel Somoza
    friend finder
    junior moderator
    wise owl
    curious george
    209 pts

    Putting this script (found on stack overflow – http://stackoverflow.com/questions/7115022/how-do-i-enumerate-all-of-the-html-ids-in-a-document-with-javascript) to run on a button click will provide an alert with all the element ID names on a page. You can probably use this as a starting point and customize it to show only what you are looking for.


    var allElements = document.getElementsByTagName(“*”);
    var allIds = [];
    for (var i = 0, n = allElements.length; i < n; ++i) {
    var el = allElements[i];
    if (el.id) { allIds.push(el.id); }



    This post has received 1 vote up.
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.