Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-09-2012, 10:54 PM   PM User | #1
Xmonster
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Xmonster is an unknown quantity at this point
syntax problem

How do I make a function like this work?

Code:
if ("parentElement".hidden=true);
 {
 ("childElement").unactive=true;
 }
Xmonster is offline   Reply With Quote
Old 07-10-2012, 01:27 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 07-10-2012, 01:47 AM   PM User | #3
Xmonster
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Xmonster is an unknown quantity at this point
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.

Code:
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' ;      
	  }      
	}
Xmonster is offline   Reply With Quote
Old 07-10-2012, 03:38 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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???
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 07-10-2012, 04:29 AM   PM User | #5
Xmonster
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Xmonster is an unknown quantity at this point
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?
Xmonster is offline   Reply With Quote
Old 07-10-2012, 07:20 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
if ("parentElement".hidden=true);

Spot the syntax errors.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 07-10-2012, 06:57 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
You can easily do
Code:
     function foo() { ... do a bunch of stuff ... }
     foo(); // call the function immediately but it's still there for later if needed
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:09 AM.


Advertisement
Log in to turn off these ads.