[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

picklist.js

Asked by knightEknight in JavaScript

Tags: javascript

<!-- 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>

<!-------------------------------------------------------------------------------------------------------------------------------------------------------------->
 
Loading Advertisement...
 
[+][-]07/16/03 10:03 AM, ID: 8936390Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: JavaScript
Tags: javascript
Sign Up Now!
Solution Provided By: jaysolomon
Participating Experts: 5
Solution Grade: A
 
[+][-]07/16/03 08:39 AM, ID: 8935434Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/16/03 10:46 AM, ID: 8936629Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/16/03 10:52 AM, ID: 8936660Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/16/03 12:17 PM, ID: 8937216Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/17/03 11:28 PM, ID: 8949532Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/05/03 10:48 AM, ID: 9082324Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/12/03 09:29 AM, ID: 9131425Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/29/03 01:46 PM, ID: 9251246Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/09/03 03:00 AM, ID: 9318754Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/03 10:03 AM, ID: 9422344Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/03 10:09 AM, ID: 9422393Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/03 10:15 AM, ID: 9422445Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/03 03:36 PM, ID: 9424609Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/24/03 04:12 PM, ID: 9424767Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93