Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    javascript conditoinal statemtent for 4 conditions

    Hi I am trying to write a JavaScript conditional statement for 4 conditions

    I currently have:


    Code:
           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?

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 498 Times in 492 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •