...

View Full Version : syntax problem



Xmonster
07-09-2012, 10:54 PM
How do I make a function like this work?



if ("parentElement".hidden=true);
{
("childElement").unactive=true;
}

Old Pedant
07-10-2012, 01:27 AM
Ummm...what does unactive mean?

And, for that matter, what does "parentElement".hidden mean? That's not even close to valid code.

Did you mean something like someElement.parentNode.style.visibility == "hidden" perhaps?

Xmonster
07-10-2012, 01:47 AM
Oh, I know its obscenely invalid, its just a placeholder, since I actually have no clue what to put there. Basically, I have this code that expands and collapses divs within an element. That element is a hidden element that shows up when the user clicks a button elsewhere on the page.

My problem is, there are three of these hidden elements, and I want the expanded elements to collapse when another hidden element is revealed, so that when the user switches between elements, the ones they've clicked on already are not shown.

The placeholder code uses the pseudo-classes set up in the function, but I don't know what sort of syntax I should be using.


window.onload = function ()
{
setupDivs( "test", "test2", "test3" );
};

function setupDivs()
{
var bob, args = arguments;

for( var i = 0; arguments[ i ]; i++ )
{
bob = document.getElementById( arguments[ i ] );

if (bob)
{
bob.className = 'unactive';
bob.getElementsByTagName( '*' )[0].onclick = f;
}
}

//??????????
{
if ("parentElement".hidden=true);
{
childNode.unactive=true;
}
}
//????????????

function f()
{
this.parentNode.className = (this.parentNode.className == 'unactive') ? 'active' : 'unactive' ;
}
}

Old Pedant
07-10-2012, 03:38 AM
Okay, so "unactive" is a class name. Fine.

But the place you are putting that pseudo-code doesn't make sense to me.

It's going to be executed *only* when the page first loads.

Is that really what you want???

Xmonster
07-10-2012, 04:29 AM
Well the rest of that code is supposed to load with the page, yes. But I didn't think of the implications of embedding that code. If I make it a separate function, is it possible to make it a self-calling function without limiting it to a startup capacity? How would you recommend doing it otherwise?

Philip M
07-10-2012, 07:20 AM
if ("parentElement".hidden=true);

Spot the syntax errors. ;)

Old Pedant
07-10-2012, 06:57 PM
You can easily do


function foo() { ... do a bunch of stuff ... }
foo(); // call the function immediately but it's still there for later if needed



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum