PDA

View Full Version : (Tutorial) Tab Content - Select All switch



sitez55
07-22-2006, 06:46 PM
1) Script Title:
Tab Content Script

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex17/tabcontent.htm

3) Describe problem:
This is an addition

For all of you that want to show all of the content contained in the tab, but don't want to repeat it for printing purposes, make this change to your tabcontent.js script. You need to cut and paste the whole function as I rearranged things.

USAGE: put a DIV named selectall in your tabs, when selected, it will display the content of all the tabs.


function expandcontent(linkobj){
var ulid=linkobj.parentNode.parentNode.id //id of UL element
var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
for (var i=0; i<ullist.length; i++){
ullist[i].className="" //deselect all tabs

linkobj.parentNode.className="selected" //highlight currently clicked on tab
if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
// HERE'S THE CHANGE - SELECTS ALL WHEN DIV="selectall"
if (linkobj.getAttribute("rel")=="selectall") {
document.getElementById(tabcontentIDs[ulid][i]).style.display="block" //expand corresponding tab content
}
}
linkobj.parentNode.className="selected" //highlight currently clicked on tab
document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function savetabcontentids(ulid, relattribute){// save ids of tab content divs
if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
tabcontentIDs[ulid]=new Array()
tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

iwdynamic
07-24-2006, 10:17 PM
Couldn't get this to work properly.

Only the added tab (rev = "selectall") will show content but all other tabs have javascript error:
Error: document.getElementById(tabcontentIDs[ulid][i]) has no properties

jscheuer1
07-27-2006, 05:58 AM
I couldn't get it to work either, see:

http://www.dynamicdrive.com/forums/showpost.php?p=45113&postcount=12

where I made up my own solution for this idea.