Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I check if my elements are visible?

Status
Not open for further replies.

Maim

Programmer
Jun 25, 1999
106
CA
No, document.getElementById(myObj).style.visible/visibility doesn't work.

Here's the situation.

I have 3 areas on my page controlled by a <select...> so if the first <option> is selected, show area 1, and so forth.
I need to validate what fields are currently visible and act upon them, but I don't want those that are not visible to have any effect on my processing.

the body onload event sets the span's style.display = 'none';
My other javascript checks for a custom tag (reqd) added to the required controls and when I click a button, I want it to return the number of required fields.
Code:
function cntVis()
{
  var iCnt = 0;
  for( index=0; index< document.all.length; index++)
  {
    oObj = document.all(index);
    if( oObj.getAttribute('reqd') )
    {
      //check if element is visible
      //do something
      iCnt ++;
    }
  }
  alert( iCnt);
}
I have tried oObj.style.visibility which returns empty always because the style is never set, only the container span is set as displayed or not.

Help? -----------------------------------
&quot;Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.&quot; - Rich Cook
 
Code:
>> //check if element is visible
if( oObj.style.display.indexOf(“block”) == 0)
  alert( “It’s visible!”);

might work, hard to tell with just this little bit

010100 1000111 1001001 1000110 [cheers]
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top