Lookup Lists: The Entire Script - Doc JavaScript | WebReference

Lookup Lists: The Entire Script - Doc JavaScript


The Entire Script

<SCRIPT LANGUAGE="JavaScript">
<!--
var NS4 = (document.layers) ? true : false;
var IE4 = (document.all) ? true : false;
var NS4MAC = NS4 &&
            (navigator.appVersion.indexOf("Macintosh") > -1);
var size = 8;
var active = false;
// select index style:
//   1. Standard
//      Selects an option if a substring match is found.
//      If no match is found, selects the closest match
//      from the bottom. For example, if the string is
//      "cz", it will match "cy...", "cx...", etc.
//   2. Explorer
//      Simulates the new index in Internet Explorer's
//      help. If the string is empty, selects the first
//      option. Otherwise, if no substring match is found
//      the selection doesn't change.
var style = 1;
start();
function site(name, url) {
  this.name = name;
  this.url = url;
}
function byName(a, b) {
  var anew = a.name.toLowerCase();
  var bnew = b.name.toLowerCase();
  if (anew < bnew) return -1;
  if (anew > bnew) return 1;
  return 0;
}
function display() {
  var list = document.organizer.list;
  if (list.selectedIndex > -1) // if an option is selected
    location.href = list.options[list.selectedIndex].value;
}
function update() {
  if ((!NS4 && !IE4) || NS4MAC) return;
  var form = document.organizer;
  var field = form.prefix;
  var list = form.list;
  field.value = list.options[list.selectedIndex].text;
}
function select(list, i) {
  if (list.selectedIndex != i) list.selectedIndex = i;
}
function checkKey() {
  if (!active) return;
  var form = document.organizer;
  var field = form.prefix;
  var list = form.list;
  var str = field.value.toLowerCase();
  if (str == "") {
    select(list, 0);
    return;
  }
  for (var i = 0; i < list.options.length; ++i) {
    if (list.options[i].text.toLowerCase().indexOf(str) == 0) {
      select(list, i);
      return;
    }
  }
  if (style == 1) {
    for (i = list.options.length - 1; i >= 0; --i) {
      if (str > list.options[i].text.toLowerCase()) {
        select(list, i);
        return;
      }
    }
    select(list, 0);
  }
}
function printList() {
  with (document) {
    write(
      '<FORM NAME="organizer" ',
      'onSubmit="display(); return false;">',
      '<TABLE BGCOLOR="#c0c0c0" CELLSPACING="0" ',
      'CELLPADDING="5" BORDER="2"><TR><TD>',
      '<TABLE BGCOLOR="#c0c0c0" CELLSPACING="0" ',
      'CELLPADDING="5" BORDER="1"><TR><TD>'
    );
    if ((NS4 || IE4) && !NS4MAC)
      write(
        '<INPUT TYPE="text" NAME="prefix" ',
        'SIZE="35" onFocus="active = true" ',
        'onBlur="active = false"><BR>'
      );
    write(
      '<SELECT NAME="list" SIZE="', size,
      '" onChange="update()">'
    );
    for (var i = 0; i < ar.length; ++i) {
      write('<OPTION VALUE="', ar[i].url, '">', ar[i].name);
    }
    write(
      '</SELECT><BR>',
      '<INPUT TYPE="submit" VALUE="Display">',
      '<INPUT TYPE="reset" VALUE="Cancel">',
      '</TD></TR></TABLE></TD></TR></TABLE></FORM>'
    );
  }
}
function start() {
  if (!window.Array) return;
  ar = new Array(); // define an array of sites
  // initialize the array
  ar[0] = new site("2ask Best of the Planet Awards",
          "http://208.5.2.150/botp/top/nomination/body.htm");
  ar[1] = new site("Ampersand",
          "http://www.arrowweb.com/amp/submit_body.html");
  ar[2] = new site("ASource",
          "http://www.asource.com/guide.html");
  ar[3] = new site("Benny Blue Web Wow Awards",
          "http://www.hsv.tis.net/~slmartin/WebWow.htm");
  ar[4] = new site("Cool Banana! Site of the Day",
          "http://www.coolbanana.com/Feedback/nominate.html");
  ar[5] = new site("Cool Site of the Day",
          "http://cool.infi.net/subscribe.html");
  ar[6] = new site("Cosmic Site of the Night",
          "http://www.adze.com/");
  ar[7] = new site("Cybersmith Site of the Day",
          "http://magneto.cybersmith.com/hotsites/suggestsite.html");
  ar[8] = new site("Dr. Webster Cool Web Site of the Day",
          "http://www.123go.com/drw/emaill.htm");
  ar[9] = new site("Dynamite Site of the Nite",
          "http://www.netzone.com/~tti/dsninfo.html");
  ar[10] = new site("Egotistical Site of the Week",
          "http://www.bibiana.com/ego.html");
  ar[11] = new site("Fred Langa's HotSpots (Windows Magazine)",
          "http://www.winmag.com/flanga/hotspots.htm");
  ar[12] = new site("Funky Site of the Day",
          "http://www.realitycom.com/cybstars/INDEXO.HTML");
  ar[13] = new site("Ground Zero",
          "http://www.ground.com/submit.html");
  ar[14] = new site("High Five",
          "http://www.highfive.com/core/submit.html");
  ar[15] = new site("Hot Rot Your Head",
          "http://www.botree.com/submit.htm");
  ar[16] = new site("iWorld Site of the Day",
          "http://www.internetnews.com/poweruser/sotd/");
  ar[17] = new site("Jayde Online",
          "http://www.jayde.com/cgi-bin/addurl.cgi");
  ar[18] = new site("Marketing Excellence",
          "http://www.focusa.com/me_award1.htm#mea");
  ar[19] = new site("NetGuide (Site of the Day or Top 100)",
          "http://www.netguide.com/aboutus/aboutreviews.html");
  ar[20] = new site("Netscape Guide by Yahoo!",
          "http://add.yahoo.com/fast/add?+Guide");
  ar[21] = new site("Netscream's UV Award",
          "http://www.netscream.com/award.htm");
  ar[22] = new site("Netsurfer Digest",
          "http://www.netsurf.com/nsd/pressroom.html");
  ar[23] = new site("New Zealand Net Awards",
          "http://www.netawards.co.nz/record.htm");
  ar[24] = new site("PC Magazine",
          "http://www8.zdnet.com/pcmag/insites/wgabout.htm");
  ar[25] = new site("Seven Wonders",
          "http://www.penncen.com/7wonders/7suggest.html");
  ar[26] = new site("The Internet RoadKill Award",
          "http://www.irk.pair.com/");
  ar[27] = new site("The Web 100",
          "http://www.web100.com/other/submit.html");
  ar[28] = new site("Too Cool",
          "http://www.toocool.com/guest/cool_add.htm");
  ar[29] = new site("USA TODAY Hot Sites",
          "http://www.usatoday.com/life/cyber/ch.htm");
  ar[30] = new site("Wave of the Day",
          "http://www.marketsquare.com/wave/");
  ar[31] = new site("WebScout",
          "http://www.webscout.com/nominate.html");
  ar[32] = new site("Wow! Web Wonders!",
          "http://www.bergen.org/AAST/Wow/submit.html");
  ar[34] = new site("Yahoo!'s Picks of the Week",
          "http://www.yahoo.com/picks/");
  ar[33] = new site("YPN Directory (and the Top 100)",
          "http://www.ypn.com/mm-bin/genobject/directory");
  if (ar.sort) ar.sort(byName);
  printList();
  if (NS4) document.captureEvents(Event.KEYUP);
  document.onkeyup = checkKey;
}
// -->
</SCRIPT>

http://www.internet.com


Created: March 11, 1998
Revised: March 11, 1998

URL: http://www.webreference.com/js/column15/code1.html