...

View Full Version : show/hide on index id



goofball1980
12-09-2010, 08:43 PM
Hello

I have the code below and I am trying to add another index id to be checked to the two that I already have. I have tried changing the line:

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

to

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

but I just get a javascript error what would be the correct syntax for a third index id?







var groupId=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';

document.getElementById(groupId+'tab_' + indx).className = 'selected';
document.getElementById(groupId+'tab_' + anotherTab).className = '';

if (indx==id+'a')
{
show (groupId+'baseballInfo_'+id);
hide (groupId+'footballInfo_'+id);
hide (groupId+'soccerInfo_'+id);
}
else if (if (indx==id+'a')
{
hide (groupId+'baseballInfo_'+id);
show (groupId+'footballInfo_'+id);
hide (groupId+'soccerInfo_'+id);
}
else
{
hide(groupId+'baseballInfo_'+id);
hide (groupId+'footballInfo_'+id);
show(groupId+'soccerInfo_'+id);



}

johnmerlino
12-09-2010, 10:36 PM
Your bent on nested ternary operators? It would be something like:

var $value = ( indx.indexOf('a') >= 0 ) ? id + 'b' : (indx.indexOf('a') <= 0) ? id + 'a' : id + 'c';

jmrker
12-09-2010, 11:13 PM
This is just a guess as to what you are trying to accomplish.

Instead of: var anotherTab = (indx.indexOf('a') >= 0) ? id + 'b' : id + 'a';
Try:


var anotherTab = id;
var indx = 'abc'.indexOf(id);
switch (indx) {
case 0 : anotherTab += 'a'; break;
case 1 : anotherTab += 'b'; break;
case 2 : anotherTab += 'c'; break;
// add more if needed ...
default : alert('Invalid ID'); break;
}

Code is untested because I don't have access to the initializing variables.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum