Advertisement

11.18.2003 at 05:43PM PST, ID: 20802201
[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!

8.8

Select box search

Asked by Noodles22 in JavaScript

Tags:

Hi,

I'm trying to write some code that will search through a select box

ie, when a select box is selected, then the user starts typing, it will jump down to an option that matches that text

Here's the code i have at the moment:

<html>
<script>
      function something(e){
            thisForm = document.test;
            thisKey = String.fromCharCode(event.keyCode);
            if(e){ // if the event object is present (NN only)
                  e = e // var e = event
            }
            else {
                  e = window.event // else e = winddow.event for IE
            }

            if(e.which){ // if there is syntax support for the property 'which' (NN only)
                  var keycode = e.which // e.which is stored in variable "keycode"
            }
            else {
                  var keycode = e.keyCode // otherwise for IE, var keycode stores e.keyCode syntax
            }

            if(keycode==8){ // keycode for backspace is 8, so if backspace is pressed,
                  if(thisForm.searchtext.value.length != 0){
                        thisForm.searchtext.value = thisForm.searchtext.value.substr(0, thisForm.searchtext.value.length-1);
                  }
            }
            else if(thisKey.match(/^[A-Za-z]+$/)){
                  thisForm.searchtext.value = thisForm.searchtext.value + String.fromCharCode(event.keyCode);
                  findMatch(thisForm.mySelect, thisForm.searchtext.value, e);
            }
      }
      
      function findMatch(selectBox, txtFind, objEvent) {
            var i;
            var s = "";
            var st2 = new String(txtFind);
            s2 = st2.toLowerCase();
            
            for (i=0; i<selectBox.options.length; i++) {
                  s = selectBox.options[i].text;
                  st = new String(s);
                  s = st.toLowerCase();
                  if (s.indexOf(s2) == 0) {
                        selectBox.selectedIndex = i-1;
                        return;
                  }
            }
      }

</script>
<body>
<form name="test">
<input type="hidden" name="searchtext" value="">
<select name="mySelect" onKeyDown="something(event);">
  <option value = "">-- Select Someone --</option>
  <option value = "">Bob Smith</option>
  <option value = "">Bob Someone</option>
  <option value = "">Joe Blow</option>
  <option value = "">Your Momma</option>
  <option value = "">Nomar Blah</option>
  <option value = "">Oma</option>
</select>
<p>
<input type="button" onclick="alert(document.test.searchtext.value)" value="test">
</form>

</body>
</html>

It almost works, the keys are recorded in the hidden field. When you type b, it jumps down to the first bob, as it normally would, but then you type o and it jumps down to oma, even though the hidden field now has "bo" in it.

Can anyone help?Start Free Trial
[+][-]11.18.2003 at 05:49PM PST, ID: 9775721

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.18.2003 at 05:49PM PST, ID: 9775723

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.18.2003 at 07:13PM PST, ID: 9776057

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.18.2003 at 08:44PM PST, ID: 9776354

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.18.2003 at 10:19PM PST, ID: 9776637

View this solution now by starting your 7-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: box
Sign Up Now!
Solution Provided By: NetGroove
Participating Experts: 3
Solution Grade: A
 
 
[+][-]11.18.2003 at 11:29PM PST, ID: 9776837

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.19.2003 at 12:47PM PST, ID: 9782225

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.19.2003 at 01:11PM PST, ID: 9782436

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32