Forum Moderators: open

Message Too Old, No Replies

2 JS Same Page

Help Please !

         

3guk

10:08 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



Ok,

I want to run 2 instances of this script [akrabat.com...]

On the same page.

So i want one set of tabs and then a bit further down another set of tabs, both containing different content.

How do I get the same script to work twice on the same page, when it comes to javascript I am about as good as cut and paste and thats it.

So if someone could tell me what to do then it would be much appreciated.

Fotiman

10:50 pm on Dec 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That script is hard coded to look for an element with a particular id value on your page and build the tabs from that. So the short answer is that you can't use this script to do what you want.

However, you could modify the script like so to potentially meet your needs.

1. Remove the call to BuildTabs() and ActivateTab(0) from the .js file.

2. Modify BuildTabs and ActivateTab functions to take a parameter with the id value of the tab container:
function BuildTabs( containerId )
function ActivateTab( containerId, activeTabIndex )

3. In both of those functions, replace this line:

tabContainer = document.getElementById('tab-container');

with this:

tabContainer = document.getElementById(containerId);

4. In your HTML file, add a function like this:

function initTabs()
{
BuildTabs('yourFirstContainer');
ActivateTab('yourFirstContainer',0);
BuildTabs('yourSecondContainer');
ActivateTab('yourSecondContainer',0);
// Add as many tab sets as you want
}

5. Call this function in your body onload event:

<body onload="initTabs();">

That should work. Good luck.

3guk

10:59 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



Wow thanks for the help.

Seems you know your stuff, could you possibly paste the modified version of tabs.js on here.

Tried to follow your instructions but I can not really understand them!

And also all of this is being called within a php page, using echo commands. Will it still work?

Fotiman

11:20 pm on Dec 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I sent you a sticky mail with the updated code as described above.