PDA

View Full Version : javascript conditoinal statemtent for 4 conditions



goofball1980
12-27-2010, 09:11 PM
Hi I am trying to write a JavaScript conditional statement for 4 conditions

I currently have:




var teamId=obj.id.substring(0, 1);
var indx=obj.id.substring(obj.id.indexOf('_')+1);
var id=indx.substring(0, indx.length-1);

var anotherTab = (indx.indexOf('a') >= 0) ? id + 'b' : id + 'a';
var anotherTab2 = (indx.indexOf('c') >= 0) ? id + 'b' : id + 'c';
var anotherTab3 = (indx.indexOf('d') >= 0) ? id + 'b' : id + 'd';


document.getElementById(teamId+'tab_' + indx).className = 'selected';
document.getElementById(teamId + 'tab_' + anotherTab).className = '';
document.getElementById(teamId + 'tab_' + anotherTab2).className = '';
document.getElementById(teamId + 'tab_' + anotherTab3).className = '';



if (indx==id+'a')
{
show (teamId+'basketballInfo_'+id);
hide(teamId + 'soccerInfo_' + id);
hide(teamId + 'footballInfo_' + id);
hide(teamId + 'baseballInfo_' + id);
}
else if(indx==id+'b')
{
hide(teamId + 'basketballInfo_' + id);
show(teamId + 'soccerInfo_' + id);
hide(teamId + 'footballInfo_' + id);
hide(teamId + 'baseballInfo_' + id);
}
else if(indx==id+'c')
{
hide(teamId + 'basketballInfo_' + id);
hide(teamId + 'soccerInfo_' + id);
hide(teamId + 'baseballInfo_' + id);
show(teamId + 'footballInfo_' + id);
}
else
{
hide(teamId + 'basketballInfo_' + id);
hide(teamId + 'soccerInfo_' + id);
hide(teamId + 'footballInfo_' + id);
show(teamId + 'baseballInfo_' + id);
}


}


I am trying to turn one tab on and have the others turned off until another tab is clicked on. It works fine if I have all 4 conditions but I need to be able to also have 3, 2, and 1. What would be an easy way to do so?

jmrker
12-28-2010, 12:24 AM
It's difficult to recreate your problem when you have provided only a portion of the code.

What does the 'hide' function look like?
What does the HTML portion contain?
Any CSS style information available?