Rotate Form Button Menu

[Total: 0    Average: 0/5]

This will create a form button that changes its label and destination when clicked at an interval.

Head Code:

<SCRIPT LANGUAGE="JavaScript">
<!-- begin
// please help yourself to this code.
var startTime   =null;
var timerID     =null;
var initial     =new Date();
var pos         =0;
var menuItem    =null;

function initArray() {
 this.length = initArray.arguments.length
   for (var i = 0; i < this.length; i++)      {
    this[i+1] = initArray.arguments[i]
   }
}

function parsemenuItem(data,num) {
 for(var i=0;i<data.length;i++)  {
  if(data.substring(i,i+1)=="|")  break;
   }
   if (num==0) return(data.substring(0,i));
   else  return(data.substring(i+1,data.length));
}

function startTimer() {
   initial = new Date();
   startTime=initial.getTime();
   stopTimer();
   menuItem = new initArray("Netscape|http://www.netscape.com",
      "JavaScript 1|http://www.js-examples.com",
      "Microsoft|http://www.microsoft.com",
      "JavaScript 2|http://www.js-examples.com",
      "IBM|http://www.ibm.com",
      "JavaScript 3|http://www.js-examples.com",
      "Yahoo|http://www.yahoo.com",
      "JavaScript 4|http://www.js-examples.com",
      "Excite|http://www.excite.com",
      "JavaScript 5|http://www.js-examples.com",
      "Hotbot|http://www.hotbot.com",
      "JavaScript 6|http://www.js-examples.com",
  "Email|mailto:notme@nowhere.nothere.net"
   );
   showTimer();
}

function stopTimer() {
   timerID=null;
   menuItem=null;
   //clearTimeout(timerID);
}

function showTimer() {
 pos= (pos == menuItem.length) ? 1 : pos + 1;
 document.forms[0].elements[0].value=parsemenuItem(menuItem[pos],0);

   timerID=window.setTimeout('showTimer()',2000);
}

function goToUrl()  {
   //parent.welcome.location=parsemenuItem(menuItem[pos],1);
   this.location=parsemenuItem(menuItem[pos],1);
   return (false);
}
// end -->
</SCRIPT>

Body Code:

This would normally be put into the body onload event<BR>
 onLoad="window.startTimer()"<BR>(and not at the bottom of the page)

<CENTER>&nbsp;</CENTER>
&nbsp;
<CENTER>
<H2>
Where To?</H2></CENTER>

<CENTER><FORM><INPUT TYPE="button" VALUE="  WHERE TO? "  NAME="goTo"
        onClick="window.goToUrl()"></FORM></CENTER>
<script>
window.startTimer();
</script>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *