function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sales LogistixSales Logistix 

Using document.getElementsbyName() in Visualforce page

I have a VisualForce page that is a drop-in element used in a standard page layout.  In my VF, I've got Javascript that's trying to get some elements of the main page and then run a pre-existing method, like this:

var imgs = document.getElementsByTagName('img');

for(var x in imgs)
  {
  if ( imgs[x].className=='hideListButton' && imgs[x].alt.indexOf("ICOMM") != -1)
     { twistSection(imgs[x]) ; }
  }

but the imgs collection is always showing up empty.  fine, I then try to use parent.document.getElementsByName() and it blows up, same thing with top.document.getElementsByName().

this code works fine if it's embedded in a JS button on the same page...but VF in this use case is somehow obscuring the parent and top pages.

The goal of this code is to make it so that some collapsible sections of the page are collapsed by default on page load.

Ideas???
kcpluspluskcplusplus
Assuming you are using the standard salesforce pageblock section, I would utilize the javascript salesforce has implemented to do this. Specifically, the javascript function called twist section. Reference - http://help.salesforce.com/apex/HTViewSolution?id=000181821&language=en_US

--KC