Link to home
Start Free TrialLog in
Avatar of flfmmqp
flfmmqp

asked on

Working with Layout

I am going to have several sectons on my webpage that I would like to allow the user to be able to maximize and minimize them as needed.  In otherwords allow them to see only what they care to see. I am using Visual Studio 2005.  The quickest example I know of is the experts-exhange "Welcome Premium Service Member" where you can minimize and maximize that section.

How can I do this without buying expensive software.  Should this be in the visual interdev section?
Avatar of flfmmqp
flfmmqp

ASKER

I am currently using this but I thought a nicer way must exist or an easier way.


<script language="javascript" type="text/javascript">
<!--


var hiddenContentClass = "extra";
var hiddenContentElement = "tbody";

function flip(e) {
  if (document.getElementById(e).style.display == 'none') {
    document.getElementById(e).style.display = '';
  } else {
    document.getElementById(e).style.display = 'none';
  }
}

function hideall() {
  for (i=0;i<document.getElementsByTagName(hiddenContentElement).length;i++) {
    if(document.getElementsByTagName(hiddenContentElement).item(i).className == hiddenContentClass){
      document.getElementsByTagName(hiddenContentElement).item(i).style.display="none";
    }          
  }
}

window.onload = function() {
  hideall();
};

// -->
</script>
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Less typing is nice; the basic idea is still the same though.  There was an error in the new code.

      el.style.display = (el.style.display == 'none') ? '' : 'none';

The closing parentheses needs to be after the "if" and before the question mark character.  That method is a simplified if statement and a great suggestion for simplifyng.

There is one other problem, I believe, that was in the original code.  I overlooked it since I thought this was more about concept.  Arrays or collections in Javascript used the square brackets instead of parentheses.  You probably need to make change like below in the hideall() function.  I will correct your original code but you could make the same change in the simplified code suggested above.

function hideall() {
  for (i=0;i<document.getElementsByTagName(hiddenContentElement).length;i++) {
    if(document.getElementsByTagName(hiddenContentElement)[i].className == hiddenContentClass){
      document.getElementsByTagName(hiddenContentElement)[i].style.display="none";
    }          
  }
}

Hopefully the recent post will bring this back to life.  Let us know if you have a question or need more info.

bol

p.s. Since were simplifying the script tag should just be ...

<script type="text/javascript">

The language property/attribute is deprecated.
bol: right you are. It's these @#$% fingers...
Badotz - LOL.  I know what you mean.  By the end of the day the Backspace key is the one that gets the most use.  If your post revitalizes this and gets the Asker to close/comment then it is worth it. :)

bol
Forced accept.

Computer101
EE Admin