javascript - Input box key Up Check (Validation) -


my array

var foo = {};     foo['xarr'] = [ "23" ];     foo['yarr'] = [ "21","21","22","23","24"];     foo['zarr']= [ "70","71","72","73","74","75" ]; 

input box takes maximum 4 character , have array object want when user enter first tow character , matches array want add class on div. if matches foo['xarr'] add diffrent class,when matches foo['yarr'] add diffrent class , on.

my html markup:

<li class="images">     <div>         <input type="text" name="cnumber1" class="inputbx" style="width:58px;" maxlength="4" size="4"/>                 </div>     <span class="test"></span> </li> 

java script

i trying through way didnt success

$('.inputbx').keydown(function() {          var inputval = $(this).val(),              ilen = inputval.length;              if( ilen >= 2){                 for(var key in foo) {                   if( foo[key].indexof(inputval) >= 0){                       if(foo[key] == 'xarr' )                           $('.images .test ').addclass('fullopactiy');                       if(foo[key] == 'yarr' )                           $('.cardimages .test ').addclass('fullopactiy');                       if(foo[key] == 'zarr' )                           $('.images .test ').addclass('fullopactiy');                   }                 }              }       }); 

something don't understand in code :

for(var key in foo) {     if( foo[key].indexof(inputval) >= 0){        if(foo[key] == 'xarr' ){             //...        }     } } 

key in foo object, it's either xarr, yarr or zarr. foo[key] number array (which makes correct sentence foo[key].indexof(inputval) >= 0). why foo[key] ever equals string 'xarr', or 'yarr'? suggest correction before continuing research :

for(var key in foo) {     var idx = foo[key].indexof(inputval); //search in array     if(  idx >= 0){        if(key == 'yarr'){             $('.cardimages .test ').addclass('fullopactiy');        }        else{           $('.images .test ').addclass('fullopacity');          }        return true;//ends search now, no need continue     } } 

i think matching algorithm suboptimal, should work

cheers

grooveek


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -