JavaScript: Getting Object Names

Hi,


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?


Thanks.

Discussion (3)

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.

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

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.

undefined

for (var i = 0, n = allElements.length; i undefined

Darrel

Discussions have been disabled for this post