Seleccionar en una llista desplegable mentre s’escriu, en Explorer < 7

Un exemple de com fer que Explorer versió anterior a la 7 (perquè la 7 ja ho fa) puga seleccionar un element d’una llista desplegable mentre s’escriu.


<html>
 <head>
  <script type="text/javascript">

   var fnd = "";
   var aux = -1;
   var saltaonchange = ’s’;

   function salta() {
    if (saltaonchange == ’s’) {
     alert(’hh’);
    }
   }   
  </script>

  <!–[if lt IE 7]>
  <script type="text/javascript">

   window.onload = function () {

    document.getElementById("desplegable").onblur = function() {
     var sel = this;

     if (aux != -1 && sel.selectedIndex != aux) {
      salta();
      aux = ”; 
     }
    } 

    document.getElementById("desplegable").onkeypress = function() {
     var k;
     var sel = this;

     k = String.fromCharCode(event.keyCode);

     if (k < " " || k > "~") return true;
     if (k == " ") fnd = "";
       else fnd += k.toUpperCase();
     for (var i=0; i<sel.options.length; i++) {

      if (fnd == sel.options[i].text.toUpperCase().substring(0,fnd.length)) {
       if (aux == -1) aux = sel.selectedIndex;
       sel.options.selectedIndex = 1;
       saltaonchange = ‘n’;
       return false;
       }
      }
     }
    }

 </script>
 <![endif]–>  

<html>

 </head>
 <body>
   <select id="desplegable" onchange="salta();" onfocus="fnd=”; aux=-1; saltaonchange=’s’">
   <option></option>
   <option>aaa</option>
   <option>bab</option>
   <option>bac</option>
   <option>cba</option>
   <option>cbb</option>
   <option>xbc</option>
   </select>
 </body>
</html>

salut.




RSS feed for comments on this post · TrackBack URL

Leave a Comment