Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > variables in Functions help...

variables in Functions help...
Thread Tools
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Jun 16, 2004, 07:49 AM
 
Hi, I'm using this function below that I cobled together from some fragments, but I'm wondering if there is a way I could group the id values so I don't have to list the state of each one as: document.getElementById("cs1").style.visibility = "visible";

that way i would have just one listing for items to make visible and another to make items invisible....

maybe I could list the combinations in variables? then just have the appropriate variable for the IDs to switch placed into the function?

//ShowHide Content
function toggleID(whichOne) {
switch(whichOne) {

//State 1
case 1:
document.getElementById("cs1").style.visibility = "visible";
document.getElementById("viewers").style.visibilit y = "hidden";

Any Ideas?
     
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Jun 16, 2004, 10:36 AM
 
I don't understand your question at all. I get that you are trying to make things visible and invisible through a JavaScript action, but the rest is totally unclear. Try writing some sudo-code.

Unless you are looking for something like this:
Code:
function doIt( theId ) { thisObjectVisibility = document.getElementById(theId).style.visibility; if(thisObjectVisibility == "visible") { thisObjectVisibility == "hidden"; } else { thisObjectVisibility == "visible"; } }
Ps... depending on whether everything on the page starts off hidden or visable, and whether you have explicitly stated this in css for the objects, you might have to change the if statement.
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 16, 2004, 01:15 PM
 
Right, I get it - this is coming from another thread where you wanted to set a number elements to be invisible and another visible, yeah?

Just put the id's in an array:

Code:
var group1 = ['el_1', 'el_2', 'el_3', 'el_4']; var group2 = ['el_5', 'el_6', 'el_7', 'el_8']; function showHide() { if (document.getElementById(group1[0]).style.visibility == "visible") { for (var i=0; i < group1.length; i++) { document.getElementById(group1[i]).style.visibility = "hidden"; document.getElementById(group2[i]).style.visibility = "visible"; } } else { for (var i=0; i < group1.length; i++) { document.getElementById(group1[i]).style.visibility = "visible"; document.getElementById(group2[i]).style.visibility = "hidden"; } } }
Two things about that - 1. it's fugly code and can be made a lot better - but that's for you to do, this is just a general concept, and 2. the above assumes the number of elements in each group is the same.

Hope that helps a little.
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:36 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2