Question

picklist.js

Asked by: knightEknight

<!-- per request, I am posting this into the public domain. -->




<HTML>
<HEAD>

<!--  1) Copy-n-paste the code between the SCRIPT tags to a file called "picklist.js"  -->
<!--  2) Include the following in your page: <SCRIPT language="javascript" src="picklist.js" ></SCRIPT>  -->
<!--  3) See the BODY tag, and the comment NOTEs in the form below for setup instructions.  -->

<SCRIPT language='javascript'>


    ////////////////////////////////////////////////////////////////////////////////
   ///// ///    Picklist.js -- (C) 1999,2003 by Ralph L. Brown (akakEk)     ///// ///
  /////   ///   This script, with copyright notice intact, may be freely   /////   ///
 /////     ///  distributed and used for any legal and legitimate         /////     ///
  /////   ///   purpose(s) except for the distribution of unsolicited      /////   ///
   ///// ///    email (spam) and the publication of pornographic content.   ///// ///
    ////////////////////////////////////////////////////////////////////////////////


var UNDEFINED;  // do not assign!

function getX(obj)
{
   return( obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft+getX(obj.offsetParent) );
}

function getY(obj)
{
   return( obj.offsetParent==null ? obj.offsetTop : obj.offsetTop+getY(obj.offsetParent) );
}

function isvalidchar(achar,validstr)
{
   if ( !validstr ) validstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 `~!@#$%^&*()_-+={}[]|:;'<>,./?\\\"";
   return( validstr.toUpperCase().indexOf(achar.toString().toUpperCase(),0) >= 0 );
}

function getQualifiedName(formElement)
{
   var formName = formElement.form.name;
   if ( formName=="" ) formName=0;  // best guess since it is indeterminate for netscape
   return 'document.forms["' + formName + '"].elements["' + formElement.name + '"]';
}


function getTooltipDiv()
{
   if ( document.getElementById )
      return document.getElementById('divPicklistTooltip');
   else if ( document.all )
      return document.all.divPicklistTooltip;
   else return null;
}


function createTooltipDiv(objSel)
{
   if ( !getTooltipDiv() )  // if this is the first time this function is
   {                        // called then create the tooltip text window.
      var tooltipDiv = "<DIV id='divPicklistTooltip' style='position:absolute;top:0px;left:0px;visibility:hidden'></div>";

      if ( document.body.insertAdjacentHTML )
      {
         document.body.insertAdjacentHTML("beforeEnd",tooltipDiv);
      }
      else if ( document.body.innerHTML )
      {
         document.body.innerHTML += tooltipDiv;
      }

      // necessary for netscape (don`t know why)
      setTimeout( "setupPicklist(" + getQualifiedName(objSel) + ")", 1 );

      return true;
   }

   return false;
}


function showTooltipText(objSel)
{
   if ( !objSel || objSel.Y==UNDEFINED )  // null or not setup
   {
      return false;
   }

   var divPicklistTooltip = getTooltipDiv();
   var s = divPicklistTooltip.innerHTML = "";

   with ( objSel )
   {
      if ( strKeyInBuf=="" && title.length )
      {
         s = '<FONT color="blue">' + title + '</font>';
      }
      else if ( selectedIndex>=0 && strKeyInBuf==options[selectedIndex].text )  // unique match found
      {
         s = '<B>' + strKeyInBuf + '</b>';
      }
      else
      {
         var c = strKeyInBuf.substring(strKeyInBuf.length-1,strKeyInBuf.length);
         c = ( c == ' ' ) ? '&nbsp;' : '<B>' + c + '</b>';
         s = strKeyInBuf.substring(0,strKeyInBuf.length-1) + c;
      }

      divPicklistTooltip.innerHTML = '<TABLE cellpadding=0 cellspacing=0 style="background-color:INFOBACKGROUND;'
        + 'font:8pt ms sans serif;padding:2px 2px 2px 2px;color:INFOTEXT;border:1px solid INFOTEXT;">'
        + '<TR><TD align="left"><NOBR>'+s+'</nobr></td></tr></table>';

      divPicklistTooltip.style.posLeft = divPicklistTooltip.style.left = X;
      divPicklistTooltip.style.posTop  = divPicklistTooltip.style.top  = Y;
      divPicklistTooltip.style.visibility = "";

   } // end with

   return true;
}


function hideTooltipText(objSel)
{
   if (objSel) objSel.strKeyInBuf = "";
   var divPicklistTooltip = getTooltipDiv();
   return divPicklistTooltip.innerHTML = "";
}


function findSelectEntry( objSel, head, tail )  // uses divide-and-conquer search, assumes sorted list
{
   with ( objSel )
   {
      if ( options.length <= 0 )
      {
         strKeyInBuf = ' <FONT color="red">No selections available.</font> ';
         showTooltipText(objSel);
         top.status = strKeyInBuf = "";
         return -1;
      }

      if ( strKeyInBuf == "" )
      {
         showTooltipText(objSel);
         return( selectedIndex = options[selectedIndex=0].text.length ? -1 : 0 );
      }

      if (head==UNDEFINED) head = 0;
      if (tail==UNDEFINED) tail = options.length-1;

      var mid = Math.round( (head+tail)/2 );

      if ( strKeyInBuf.toUpperCase() == options[mid].text.substring(0,strKeyInBuf.length).toUpperCase() )
      {
         while ( (mid>0)  &&  strKeyInBuf.toUpperCase() == options[mid-1].text.substring(0,strKeyInBuf.length).toUpperCase() )
         {
            mid--;  // get the topmost matching item in the list, not just the first found
         }

         selectedIndex = mid;

         top.status = strKeyInBuf = options[mid].text.substring(0,strKeyInBuf.length);

         if ( mid == Math.round( (head+tail)/2 ) )  // if the original mid is an exact match
         {
            if ( (mid==tail) || ( (mid<tail) && strKeyInBuf.toUpperCase() != options[mid+1].text.substring(0,strKeyInBuf.length).toUpperCase() ) )
            {
               top.status = strKeyInBuf = options[mid].text;  // unique match found
            }
         }

         showTooltipText(objSel);

         return selectedIndex;
      }

      if ( head >= tail )  // then since no exact match was found, go back to previous strKeyInBuf (thus the length-1)
      {
         strKeyInBuf = strKeyInBuf.substring(0,strKeyInBuf.length-1)
         return findSelectEntry( objSel );
      }

      if ( strKeyInBuf.toUpperCase() < options[mid].text.substring(0,strKeyInBuf.length).toUpperCase() )
      {
         return findSelectEntry( objSel, head, Math.max(head,mid-1) );
      }

      return findSelectEntry( objSel, Math.min(mid+1,tail), tail );
   }  // end with
}


function picklistFocusHandler(e)
{
   var event = e ? e : window.event;  // to handle both NS and IE events
   var objSel = event.target ? event.target : event.srcElement;
   picklistFocusHandler.objSel = objSel;

   // update data elements
   objSel.X = getX(objSel)+2;
   objSel.Y = getY(objSel)-20;
   objSel.strKeyInBuf = "";

   // display the tooltip help (the title attribute by default)
   showTooltipText(objSel);
}


function picklistBlurHandler(e)
{
   var event = e ? e : window.event;  // to handle both NS and IE events
   var objSel = event.target ? event.target : event.srcElement;
   picklistFocusHandler.objSel = null;

   top.status = (objSel.selectedIndex>-1) ? objSel.options[objSel.selectedIndex].text : "";
   hideTooltipText(objSel);

   return true;
}


function picklistMouseOverHandler(e)
{
   var event = e ? e : window.event;  // to handle both NS and IE events
   var objSel = event.target ? event.target : event.srcElement;

   showTooltipText(objSel);

   return true;
}


function picklistMouseOutHandler(e)
{
   var event = e ? e : window.event;  // to handle both NS and IE events
   var objSel = event.target ? event.target : event.srcElement;

   if ( objSel==picklistFocusHandler.objSel || objSel==document.activeElement )
      return true;

   hideTooltipText();

   return true;
}


function picklistKeyDownHandler(e)
{
   var event = e ? e : window.event;  // to handle both NS and IE events
   var objSel = event.target ? event.target : event.srcElement;
   var divPicklistTooltip = getTooltipDiv();

   with ( objSel )
   {
      // this is to correct the search bug when the list is left open after single-click
      if ( strKeyInBuf=="" && event.keyCode>40 )
      {
         objSel.blur();
         objSel.focus();
      }

      switch(event.keyCode)
      {
        case(8):  // backspace
        {
           if ( selectedIndex>=0 && strKeyInBuf==options[selectedIndex].text )
           {
              top.status = strKeyInBuf = "";
           }
           else
           {
              top.status = strKeyInBuf = strKeyInBuf.substring(0,strKeyInBuf.length-1);
           }

           selectedIndex = findSelectEntry(objSel);

           event.keyCode = 0;
           return false;
        }

        case(9):   // tab
        case(13):  // enter
        {
           event.keyCode = 9;  // convert enter to tab
           return true;
        }

        case(27):  // escape
        {
           top.status = strKeyInBuf = "";
           selectedIndex = options[selectedIndex=0].text.length ? -1 : 0;
           showTooltipText(objSel);

           event.keyCode = 0;
           return false;
        }

        case(32):  // space
        {
           top.status = strKeyInBuf += ' ';
           // this must be fired explicitely for spaces
           return !picklistKeyPressHandler(event);
        }

        // I don't know if these are universal
        case(33):  // page up
        case(34):  // page down
        case(35):  // end
        case(36):  // home
        case(37):  // left arrow
        case(38):  // up arrow
        case(39):  // right arrow
        case(40):  // down arrow
        {
           top.status = hideTooltipText(objSel);
           return true;
        }

      }  // end switch
   }  // end with

   return true;
}


function picklistKeyPressHandler(e)
{
   var event = e ? e : window.event;  // to handle both NS and IE events
   var objSel = event.target ? event.target : event.srcElement;
   var inputChar = String.fromCharCode(event.keyCode ? event.keyCode : event.charCode);

   if ( inputChar=='\n' || inputChar=='\r' )
   {
      top.status = objSel.strKeyInBuf = ( objSel.selectedIndex>-1 ? objSel.options[objSel.selectedIndex].text : "" );
   }

   if ( isvalidchar(inputChar) && event.charCode!=0 )
   {
      objSel.strKeyInBuf += inputChar;

      // must use setTimeout to override the default SELECT keypress event(s)
      setTimeout( "findSelectEntry(" + getQualifiedName(objSel) + ")", 1 );
   }

   return true;
}


function setupPicklist(objSel)
{
   if ( !document.all && !document.getElementById )
      return false;  // browser not supported

   if ( !objSel || (""+objSel.type).substring(0,6).toLowerCase()!="select" )
      return false;  // null or not a select

   createTooltipDiv(objSel);

   // create/init data elements
   objSel.X = getX(objSel)+2;
   objSel.Y = getY(objSel)-20;
   objSel.strKeyInBuf = "";

   // setup event handlers
   objSel.onclick     = function(){top.status=hideTooltipText(this);}
   objSel.onfocus     = picklistFocusHandler;
   objSel.onblur      = picklistBlurHandler;
   objSel.onmouseover = picklistMouseOverHandler;
   objSel.onmouseout  = picklistMouseOutHandler;
   objSel.onkeydown   = picklistKeyDownHandler;
   objSel.onkeypress  = picklistKeyPressHandler;
   objSel.onkeyup     = null;

   return true;
}


/////////////////////////////////// -- End Picklist.js -- ////////////////////////////////////////

</SCRIPT>
</HEAD>

<BODY onLoad="setupPicklist(document.myForm.myPicklist1); setTimeout('document.myForm.myPicklist1.focus()',1);"  comment="use setTimeout for Netscape focus" >

<CENTER>
<P align="center">&nbsp;</P>
<P align="center">&nbsp;</P>
<P align="center">&nbsp;</P>

<FORM name="myForm">

 <!-- NOTE: The options in the SELECT must be ordered by the .text property! -->
 <!-- NOTE: The .value properties can be anything you want. -->

 <SELECT name="myPicklist1" size="1"  title="Please type your name in the pick-list below." >
  <OPTION value="whatever"></OPTION>
  <OPTION>Abe</OPTION>
  <OPTION>Alice</OPTION>
  <OPTION>Alicia</OPTION>
  <OPTION>Allen</OPTION>
  <OPTION>Arthur</OPTION>
  <OPTION>Arty</OPTION>
  <OPTION>Beatrice</OPTION>
  <OPTION>Ben</OPTION>
  <OPTION>Bill</OPTION>
  <OPTION>Bing</OPTION>
  <OPTION>Brian</OPTION>
  <OPTION>Brittany</OPTION>
  <OPTION>Bruce</OPTION>
  <OPTION>Buzz</OPTION>
  <OPTION>Carie</OPTION>
  <OPTION>Catherine</OPTION>
  <OPTION>Cathy</OPTION>
  <OPTION>Charles</OPTION>
  <OPTION>Chase</OPTION>
  <OPTION>Chris</OPTION>
  <OPTION>Christian</OPTION>
  <OPTION>Christina</OPTION>
  <OPTION>Christopher</OPTION>
  <OPTION>Clay</OPTION>
  <OPTION>Clayton</OPTION>
  <OPTION>Daniel</OPTION>
  <OPTION>Danny</OPTION>
  <OPTION>Darren</OPTION>
  <OPTION>Darryl</OPTION>
  <OPTION>Darwin</OPTION>
  <OPTION>David</OPTION>
  <OPTION>Dean</OPTION>
  <OPTION>Derrick</OPTION>
  <OPTION>Dinah</OPTION>
  <OPTION>Don</OPTION>
  <OPTION>Doug</OPTION>
  <OPTION>Eathen</OPTION>
  <OPTION>Ed</OPTION>
  <OPTION>Edward</OPTION>
  <OPTION>Edwin</OPTION>
  <OPTION>Evan</OPTION>
  <OPTION>Forrest</OPTION>
  <OPTION>Frank</OPTION>
  <OPTION>Fritz</OPTION>
  <OPTION>Gary</OPTION>
  <OPTION>George</OPTION>
  <OPTION>Glenn</OPTION>
  <OPTION>Greg</OPTION>
  <OPTION>Hank</OPTION>
  <OPTION>Hellen</OPTION>
  <OPTION>Henry</OPTION>
  <OPTION>Imus</OPTION>
  <OPTION>Ingred</OPTION>
  <OPTION>Jack</OPTION>
  <OPTION>Jack Club</OPTION>
  <OPTION>Jack Diamond</OPTION>
  <OPTION>Jack Heart</OPTION>
  <OPTION>Jack Spade</OPTION>
  <OPTION>Jackie</OPTION>
  <OPTION>Jacob</OPTION>
  <OPTION>James</OPTION>
  <OPTION>Jason</OPTION>
  <OPTION>Jean-Luc</OPTION>
  <OPTION>Jerry</OPTION>
  <OPTION>Jesus</OPTION>
  <OPTION>Jim</OPTION>
  <OPTION>John</OPTION>
  <OPTION>Katlyn</OPTION>
  <OPTION>Kayla</OPTION>
  <OPTION>Kendra</OPTION>
  <OPTION>Kyle</OPTION>
  <OPTION>Lance</OPTION>
  <OPTION>Larry</OPTION>
  <OPTION>Leah</OPTION>
  <OPTION>Lenny</OPTION>
  <OPTION>Luke</OPTION>
  <OPTION>Mallory</OPTION>
  <OPTION>Mandy</OPTION>
  <OPTION>Mark</OPTION>
  <OPTION>Mary</OPTION>
  <OPTION>MaryAnn</OPTION>
  <OPTION>Matthew</OPTION>
  <OPTION>Michael</OPTION>
  <OPTION>Michele</OPTION>
  <OPTION>Mickey</OPTION>
  <OPTION>Mike</OPTION>
  <OPTION>Mitch</OPTION>
  <OPTION>Nathan</OPTION>
  <OPTION>Ned</OPTION>
  <OPTION>Olive</OPTION>
  <OPTION>Ollie</OPTION>
  <OPTION>Oppie</OPTION>
  <OPTION>Pat</OPTION>
  <OPTION>Paul</OPTION>
  <OPTION>Perry</OPTION>
  <OPTION>Peter</OPTION>
  <OPTION>Phil</OPTION>
  <OPTION>Phillip</OPTION>
  <OPTION>Rachael</OPTION>
  <OPTION>Ralph</OPTION>
  <OPTION>Randall</OPTION>
  <OPTION>Randy</OPTION>
  <OPTION>Rebekah</OPTION>
  <OPTION>Red</OPTION>
  <OPTION>Rex</OPTION>
  <OPTION>Rick</OPTION>
  <OPTION>Ried</OPTION>
  <OPTION>Robert</OPTION>
  <OPTION>Rodney</OPTION>
  <OPTION>Roger</OPTION>
  <OPTION>Sally</OPTION>
  <OPTION>Sam</OPTION>
  <OPTION>Sharon</OPTION>
  <OPTION>Sidney</OPTION>
  <OPTION>Stephen</OPTION>
  <OPTION>Steve</OPTION>
  <OPTION>Stuart</OPTION>
  <OPTION>Ted</OPTION>
  <OPTION>Terry</OPTION>
  <OPTION>Theodore</OPTION>
  <OPTION>Theresa</OPTION>
  <OPTION>Thomas</OPTION>
  <OPTION>Tim</OPTION>
  <OPTION>Tom</OPTION>
  <OPTION>Val</OPTION>
  <OPTION>Van</OPTION>
  <OPTION>Vince</OPTION>
  <OPTION>Wayne</OPTION>
  <OPTION>Will</OPTION>
  <OPTION>William</OPTION>
  <OPTION>Wink</OPTION>
  <OPTION>Woody</OPTION>
  <OPTION>X</OPTION>
  <OPTION>Yoda</OPTION>
  <OPTION>Zack</OPTION>
  <OPTION>Ziggy</OPTION>
  <OPTION>Zurg</OPTION>
 </SELECT>

<P><INPUT type="submit" value="Reload" /></P>

</FORM>

</CENTER>

</BODY>
</HTML>

<!-------------------------------------------------------------------------------------------------------------------------------------------------------------->

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-07-16 at 08:13:21ID20680352
Tags

javascript

Topic

JavaScript

Participating Experts
5
Points
20
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. For Tom
    Hi Tom, Thank for your help. Regards, Wang
  2. FOR TOM
    Hi Tom Sorry but i don't have more points available at this time. I will post more points as soon as i get them. Thanks.
  3. For Gns / Glenn -- 11469898
    Hi Glenn, please make a comment so I can give you the 200 points I think you deserve! Ingmar.
  4. Question for Glenn
    Thanks again, Glenn

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: knightEknightPosted on 2003-07-16 at 08:39:03ID: 8935434

 

by: jaysolomonPosted on 2003-07-16 at 10:03:34ID: 8936390

kEk

Awsome script

Definately going in my toolbox

Great job

I would proly give you 500 points for this :>)

 

by: AcklenXPosted on 2003-07-16 at 10:46:24ID: 8936629

but it's still not a combo box!!

;)

 

by: knightEknightPosted on 2003-07-16 at 10:52:33ID: 8936660

doesn't claim to be :)  However, that is a doable thing -- at least in IE.  I'll have to investigate it for NS.

 

by: jaysolomonPosted on 2003-07-16 at 12:17:57ID: 8937216

i investigated NS7.02 works like a charm

thanks for the point kEk

jAy

 

by: mplungjanPosted on 2003-07-17 at 23:28:47ID: 8949532

I'll just post this for people who needs a smaller script
<HTML>
<HEAD>
<TITLE>Combo Box</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!-- // cloak
/* (c) 1999-2003 Michel Plungjan  "michel at irt.org"
   comments, bugs or improvements welcome */

function checkIt(theValue,theSelect) {
   var theIndex = theSelect.selectedIndex;
   if (theIndex ==-1) theIndex = 0;
   for (var i=0,n=theSelect.options.length;i<n;i++) {
//    if (theSelect.options[i].texttoLowerCase().indexOf(theValue.toLowerCase()) == 0) { // case INsensitive
      if (theSelect.options[i].text.indexOf(theValue) == 0) { // case sensitive
         theSelect.selectedIndex=i;
         break;
      }
   }
}

// uncloak --></SCRIPT>
</HEAD>
<BODY onLoad="document.myform.inputField.focus()">
Start typing (case sensitive)
<FORM NAME="myform" onSubmit="return false">
<INPUT NAME="inputField" TYPE="TEXT" SIZE=10 onKeyUp="checkIt(this.value,this.form.List)">
<BR><SELECT NAME="List" SIZE="10" onChange="this.form.inputField.value=this.options[this.selectedIndex].text">
<OPTION>A
<OPTION>Apple
<OPTION>Applicable
<OPTION>Application
<OPTION>B
<OPTION>Banana
</SELECT>
</FORM>
</BODY>
</HTML>

 

by: knightEknightPosted on 2003-08-05 at 10:48:29ID: 9082324

/*
 more bonus material ...
 The .js file below will sort the options in a SELECT, simply do this:  qsortSelect(objSelect);
 You can use this to sort a SELECT before you initialize it as a PickList.
*/



 var UNDEFINED;  // do not assign!

 function copyOpt( srcOpt, destOpt )
 {
    if (!srcOpt)  return null;
    if (!destOpt) return new Option(srcOpt.text,srcOpt.value,srcOpt.defaultSelected,srcOpt.selected);
    destOpt.value = srcOpt.value;
    destOpt.text  = srcOpt.text;
    destOpt.selected = srcOpt.selected;
    destOpt.defaultSelected = srcOpt.defaultSelected;
    return destOpt;
 }


 function swapOpt( opt1, opt2 )
 {
    if ( opt1 == opt2 ) return false;

    var tmp = copyOpt( opt1 );
    copyOpt( opt2, opt1 );
    copyOpt( tmp, opt2 );

    return true;
 }


 function qsortSelect( objSelect, head, tail )
 {
    if (head==UNDEFINED) head = 0;
    if (tail==UNDEFINED) tail = objSelect.options.length;
   
    if ( head+1 < tail ) with ( objSelect )
    {
       var prevlow = head;

       for ( var i=head+1; i<tail; ++i )
       {
          if ( options[i].text.toUpperCase() < options[head].text.toUpperCase() )
          {
             swapOpt( options[i], options[++prevlow] );
          }
       }

       swapOpt( options[head], options[prevlow] );

       qsortSelect( objSelect, head, prevlow );
       qsortSelect( objSelect, prevlow+1, tail );
    }
 }

 

by: knightEknightPosted on 2003-08-12 at 09:29:25ID: 9131425

 

by: PhrogzPosted on 2003-08-29 at 13:46:30ID: 9251246

 

by: xangelusxPosted on 2003-09-24 at 10:03:21ID: 9422344

I just started working on a true HTML combo box.  It's pretty limited in it's current implimentation, but I've already started expanding on it.  Try it out and let me know if you notice any bugs.  I've tested it on Firebird 0.6 and IE 6.0 for the PC

http://www.csb7.com/samples/HTMLComboBox.htm

 

by: jaysolomonPosted on 2003-09-24 at 10:09:26ID: 9422393

x

In my IE6 all i get is a textbox, don't see anything whatsoever pop up

 

by: xangelusxPosted on 2003-09-24 at 10:15:41ID: 9422445

Jay,  I just sent you an email regarding your comment.

 

by: mplungjanPosted on 2003-09-24 at 15:36:49ID: 9424609

Nice in Mozilla

 

by: xangelusxPosted on 2003-09-24 at 16:12:36ID: 9424767

Thanks, MP.  I hadn't gotten around to testing it in Moz yet.  It appears safe in IE 5.5 - 6.0, NS 6 - 7 and the current version of Firebird, though Jay still can't seem to get it to work on his copy of IE.  It also degrades nicely in NS 4.7x.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...