having true/false trouble with visibility of DIV

L

lkrubner

In the first version of this function, I only test for true or false,
on a global var, without limiting that true or false to the id of a
particular item. What this meant was that if you were using this
function for several items on a page, sometimes you had to click twice
and other times you only had to click once, because sometimes
visibility was false though you were clicking on an item that was true.
So then I started adding the id's of each item on a page to the object
isDivVisible. My goal was that the true/false status of visibility
should be specific to each item. Yet I find I'm still having to click
twice. Where is the flaw in the logic of the code I wrote?





isDivVisible = new Object();
function hideOrShowDiv(elementPointer) {
var divId = elementPointer.id;
if (document.getElementById(divId)) {
var optionDiv = document.getElementById(divId);

// 12-30-04 - we need isDivVisible to remember a different
// visibility state for each div on the page, so we use
// Javascript's hash-like syntax to keep track of each
// div as if the various states were being stored in an array

if (isDivVisible.divId) {
if (isDivVisible["divId"] == true) {
optionDiv.style.visibility='hidden';
optionDiv.style.height='0px';
optionDiv.style.width='0px';
optionDiv.style.overflow='auto';
optionDiv.style.display='none';
isDivVisible["divId"] = false;
} else {
optionDiv.style.visibility='visible';
optionDiv.style.height='auto';
optionDiv.style.width='auto';
optionDiv.style.overflow='auto';
optionDiv.style.display='block';
isDivVisible["divId"] = true;
}
} else {
optionDiv.style.visibility='visible';
optionDiv.style.height='auto';
optionDiv.style.width='auto';
optionDiv.style.overflow='auto';
optionDiv.style.display='block';
isDivVisible["divId"] = true;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top