 |
 |
variables in Functions help...
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
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
|
|
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
|
|
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
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |