Hi,
I am fairly new to Javascript and am having trouble making the following work.
I have the following function.
function fnStartInterval(){
intervalID = window.setInterval(“tabview_switch(‘tabview’,X)”, 5000);
function tabview_switch(TabViewId, id) { tabview_aux(TabViewId, id); }
}
* X should be the value 1, 2 or 3.
Within the “setInterval” code, I would like to test the value of “tabview”.
If it is 1 then I want to call this function … tabview_switch(‘tabview’,2)
If it is 2 then I want to call this function … tabview_switch(‘tabview’,3)
If it is 3 then I want to call this function … tabview_switch(‘tabview’,1)
The result should be that my three tabs keeps changing from one to the next every few seconds.
Any ideas?
Thanks,
Steve
[CODE]var CurTab = 1;
var MaxTab = 3;
function StartTabFlip(iTime)
{
var intervalID = window.setInterval("NextTab('tabview', CurTab);", 5000);
}
function NextTab(TabViewId, id)
{
CurTab++;
if(CurTab > MaxTab) CurTab -= MaxTab;
tabview_aux(TabViewId, id); <---- ???? Why not just add whatever code that is here?
}
}[/CODE]
Can't add anything else without understanding what "tabs" are, but that should be easily modified back into whatever you need.[CODE]<script type="text/javascript">
tabview_initialize('TabView');
</script>[/CODE]
Try renaming everything back into suiting the tab naming style("fnStartInterval", etc.). Now that I think about it, it looks like that code was made for Netscape 4, but that makes my chances of understanding how to add what you want even worse.[CODE]
<!--
// Additional Code to Rotate Tabs
var intervalID = "";
var CurTab = (Math.round((Math.random()*2)+1));
var MaxTab = 3;
function fnStartInterval(){
intervalID = window.setInterval("fnRecycle()", 5000);
}
function fnRecycle(){
CurTab++;
if(CurTab > MaxTab) CurTab -= MaxTab;
tabview_initialize('TabView');
tabview_switch('tabview',CurTab);
}
function fnStopInterval(){
if(intervalID!=""){
window.clearInterval(intervalID);
intervalID="";
}
}
// ----- Original Code for Tab View Navigation -----
function tabview_aux(TabViewId, id)
{
var TabView = document.getElementById(TabViewId);
// ----- Tabs -----
var Tabs = TabView.firstChild;
while (Tabs.className != "Tabs" ) Tabs = Tabs.nextSibling;
var Tab = Tabs.firstChild;
var i = 0;
do
{
if (Tab.tagName == "A")
{
i++;
Tab.href = "javascript:tabview_switch('"+TabViewId+"', "+i+");";
Tab.className = (i == id) ? "Active" : "";
Tab.blur();
}
}
while (Tab = Tab.nextSibling);
// ----- Pages -----
var Pages = TabView.firstChild;
while (Pages.className != 'Pages') Pages = Pages.nextSibling;
var Page = Pages.firstChild;
var i = 0;
do
{
if (Page.className == 'Page')
{
i++;
if (Pages.offsetHeight) Page.style.height = (Pages.offsetHeight-2)+"px";
Page.style.overflow = "auto";
Page.style.display = (i == id) ? 'block' : 'none';
}
}
while (Page = Page.nextSibling);
}
// ----- Functions -------------------------------------------------------------
function tabview_switch(TabViewId, id) { tabview_aux(TabViewId, id); }
function tabview_initialize(TabViewId) { tabview_aux(TabViewId, CurTab); }
//-->
[/CODE]
[CODE]<script type="text/javascript">
tabview_initialize('TabView');
</script>[/CODE]
On my Firefox it's flipping tabs, but it gets caught in two endless loops during page load. The code looks mostly Netscape 4 compatible, but then I started thinking...is getElementById supported by Netscape 4? Nope, so that means all that code can be changed. ? [CODE]<div class="Page1">
<div class="tri_1"><img src="images/pixel.gif" width="1" height="1" alt="" border="0"></div>
<table border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="104" align="center" valign="middle" class="eleven"><a href="http://www.didax.com/178-2986"><img src="images/images_sm/178-2986thbnl.gif" border="0" alt="Numero Single Pack" align="absmiddle"></a><br><img src="images/pixel.gif" width="1" height="5" alt="" border="0"><br><a href="http://www.didax.com/178-2986">Numero Single Pack</a></td>
<td width="104" align="center" valign="middle" class="eleven"><a href="http://www.didax.com/195-163"><img src="images/images_sm/195-163thbnl.jpg" border="0" alt="Place Value Flip Stand" align="absmiddle"></a><br><img src="images/pixel.gif" width="1" height="5" alt="" border="0"><br><a href="http://www.didax.com/195-163">Place Value Flip Stand</a></td>
<td width="104" align="center" valign="middle" class="eleven"><a href="http://www.didax.com/2-146"><img src="images/images_sm/2-146thbnl.gif" border="0" alt="Math, Literature and Unifix®" align="absmiddle"></a><br><img src="images/pixel.gif" width="1" height="5" alt="" border="0"><br><a href="http://www.didax.com/2-146">Math, Literature and Unifix®</a></td></tr><tr>
<td width="104" align="center" valign="middle" class="eleven"><a href="http://www.didax.com/2-25"><img src="images/images_sm/2-25thbnl.jpg" border="0" alt="100 Unifix Cubes" align="absmiddle"></a><br><img src="images/pixel.gif" width="1" height="5" alt="" border="0"><br><a href="http://www.didax.com/2-25">100 Unifix Cubes</a></td>
<td width="104" align="center" valign="middle" class="eleven"><a href="http://www.didax.com/2-5165"><img src="images/images_sm/2-5165thbnl.gif" border="0" alt="Mathematics Today" align="absmiddle"></a><br><img src="images/pixel.gif" width="1" height="5" alt="" border="0"><br><a href="http://www.didax.com/2-5165">Mathematics Today</a></td>
<td width="104" align="center" valign="middle" class="eleven"><a href="http://www.didax.com/2-5239"><img src="images/images_sm/2-5239thbnl.gif" border="0" alt="Addition" align="absmiddle"></a><br><img src="images/pixel.gif" width="1" height="5" alt="" border="0"><br><a href="http://www.didax.com/2-5239">Addition</a></td>
</tr>
<tr><td align="center" valign="middle" colspan="3" height="12"><img src="images/pixel_mdblue.gif" width="322" height="1" alt="" border="0"></td></tr>
<tr>
<td align="center" colspan="3" class="eleven"><span class="elevenbolddkgrey">View Math Products by Grade:</span><br><img src="images/pixel.gif" width="1" height="3" alt="" border="0"><br><a href="http://www.didax.com/shop/searchresults.cfm/GradeID/-1/SubjectID/3/.cfm" title="Pre K">Pre K</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/0/SubjectID/3/.cfm" title="Kindergarten">K</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/1/SubjectID/3/.cfm" title="Grade 1">1</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/2/SubjectID/3/.cfm" title="Grade 2">2</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/3/SubjectID/3/.cfm" title="Grade 3">3</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/4/SubjectID/3/.cfm" title="Grade 4">4</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/5/SubjectID/3/.cfm" title="Grade 5">5</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/6/SubjectID/3/.cfm" title="Grade 6">6</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/7/SubjectID/3/.cfm" title="Grade 7">7</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/8/SubjectID/3/.cfm" title="Grade 8">8</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/9/SubjectID/3/.cfm" title="Grade 9">9</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/10/SubjectID/3/.cfm" title="Grade 10">10</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/11/SubjectID/3/.cfm" title="Grade 11">11</a> <a href="http://www.didax.com/shop/searchresults.cfm/GradeID/12/SubjectID/3/.cfm" title="Grade 12">12</a> <br><img src="images/pixel.gif" width="1" height="10" alt="" border="0"><br><a href="http://www.didax.com/shop/searchresults.cfm/SubjectID/3/CategoryID/1/.cfm" title="Math Products on Sale!" class="elevenboldred">Math Products on Sale!</a></td>
</tr>
</table>
</div>[/CODE]
[CODE]function tabview_aux(IDnumber)
{
if(IDnumber != 1) document.getElementById("Tab1").style.display = 'none';
if(IDnumber != 2) document.getElementById("Tab2").style.display = 'none';
if(IDnumber != 3) document.getElementById("Tab3").style.display = 'none';
document.getElementById("Tab"+IDnumber).style.display = 'block';
}[/CODE]
[CODE]function tabview_aux(iNewTab, iCurTab)
{
if(iNewTab != iCurTab)
{
var OldTab = document.getElementById('Tab'+iCurTab);
var NewTab = document.getElementById('Tab'+iNewTab);
OldTab.style.display = 'none';
NewTab.style.display = 'block';
}
}[/CODE]
Hopefully removing the loops will fix them being endless. ?Here is the link to the original code[/quote]
0.1.9 — BETA 5.19