Menu constructor

[Total: 0    Average: 0/5]

This script produced an alphabetically ordered menu from an unordered list of hyperlinks. A must for big sites!!

Body Code:

<script language="Javascript">

function hyper (omschrijving,link)
{
  this.omschrijving =omschrijving;
  this.link = link;
}

var menu = new Array();
menu[0]=new hyper("Yahoo","http://www.yahoo.com");
menu[1]=new hyper("Altavista","http://www.altavista.com");
menu[2]=new hyper("Excite","http://www.excite.com");
menu[3]=new hyper("Advalvas","http://www.advalvas.com");
menu[4]=new hyper("Hotbot","http://www.hotbot.com");
menu[5]=new hyper("Lycos","http://www.lycos.be");
menu[6]=new hyper("Britanica","http://www.britanica.com");
menu[7]=new hyper("Msm","http://www.msm.com");
menu[8]=new hyper("Mapguest","http://www.mapguest.com");
menu[9]=new hyper("Google","http://www.google.com");
var i=0;
var j=0;
hulp=new hyper("hulp","hulp");

while(j < menu.length -1)
{
  i=0;
  j=0;
  while(i < menu.length -1)
    {
      if (menu[i].link > menu[i+1].link) {
        hulp = menu[i];
        menu[i]= menu[i+1];
        menu[i+1]=hulp;}
      else
       {j++;}
     i++;
     }   
}

document.write("<a name=index>");
oudbegin=""
for(i=0;i<menu.length;i++)
{
begin = menu[i].omschrijving.substring(0,1);
if (oudbegin != begin)
  {
   document.write("<a href=#"+begin+">"+begin+"</a><br> ");
   oudbegin=begin;
  }
}

document.write("------------------");

oudbegin=""
for(i=0;i<menu.length;i++)
{
begin = menu[i].omschrijving.substring(0,1);
if (oudbegin != begin)
  {
   document.write("<a name="+begin+">");
   document.write("<br> <a href=#index>"+begin+"</a><br>");
   oudbegin=begin;
  }
document.write("<a href="+menu[i].link+" target = frame>"+menu[i].omschrijving+"</a> <br>");
}
</script>

Times Viewed: 1

Leave a Reply

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