javascript - TypeError: name.toLowerCase is not a function -
i creating auto-complete code list countries json array. works fine, error in console. don't know when harmful. please can solve this?
css
.mainpart { width:100%; height:auto; } .first { width:150px; height:25px; float:left } .second { width:150px; height:25px; float:left } ul, li { list-style:none; } .li-autolist { background-color:#cbcacc; border:1px solid #fff; cursor:pointer; }
html
<div class="mainpart"> <div class="first"> <input type="text" id="county" onclick="autolist('#county','country')" /> </div> <div class="second"> <input type="text" id="county2" onclick="autolist('#county2','city')" /> </div> </div>
js
<script type="text/javascript"> function autosort(id,list){ if(list=='country'){ county=(co.response.data); }else{ county=(ci.response.data); } li=''; for(i=0;i<county.length;i++){ c=$(id).val().touppercase().replace(/["'\(\)]/g, ""); condec=county[i].description+'('+county[i].cod+')'; condec=condec.touppercase().replace(/["'\(\)]/g, ""); n=(condec.search(c)); if(n>=0){ cname=county[i].description+'('+county[i].cod+')'; li+='<li class="li-autolist"><input type="checkbox" class="itm" value="'+county[i].description+'('+county[i].cod+')">'+county[i].description+'</li>'; } } $('.li-autolist').remove(); $(id).after(li); } function autolist(id,list){ if(list=='country'){ county=(co.response.data); }else{ county=(ci.response.data); } li=''; for(i=0;i<county.length;i++){ c=$(id).val().touppercase().replace(/["'\(\)]/g, ""); condec=county[i].description+'('+county[i].cod+')'; condec=condec.touppercase().replace(/["'\(\)]/g, ""); n=(condec.search(c)); chk=''; if(condec==c){ chk='checked'; } cname=county[i].description+'('+county[i].cod+')'; li+='<li class="li-autolist liitm"><input type="checkbox" '+chk+' class="itm" value="'+county[i].description+'('+county[i].cod+')">'+county[i].description+'</li>'; } $('.li-autolist').remove(); $(id).after(li); $('.itm').click(function(){ $(id).val( $(this).val()); $('.li-autolist').remove(); // autolist(id,list); }); $('.liitm').click(function(){ // $(id).val( $(this).val()); var cb = $(this).find(":checkbox")[0]; $(id).attr('checked',true); $(id).val( $(cb).val()); $('.li-autolist').remove(); // autolist(id,list); }); $(id).bind({ 'keyup': function() { $('.itm').removeattr('checked'); autosort(id,list) }, blur: function() { //if checkbox checked if(!$('.itm').attr('checked'&&( $(id).val()==''))){ $(id).val(null); autolist(id,list) } } }); } var ci={"response":{"status":"0", "data":[{"cod":"slst" ,"description":"san luis talpa" , "group":"sv"},{"cod":"sa6" ,"description":"san salvador" , "group":"sv"}]}}; var co={"response":{"status":"0", "data":[{"cod":"fr-ag" ,"description":"agay" , "group":"altro"},{"cod":"fr-ai" ,"description":"aix en provence" , "group":"altro"},{"cod":"al" ,"description":"albania" , "group":"le piĆ¹ cliccate"},{"cod":"dz" ,"description":"algeria" , "group":"altro"},{"cod":"fr-am" ,"description":"amiens" , "group":"altro"},{"cod":"ad" ,"description":"andorra" , "group":"altro"},{"cod":"zw" ,"description":"zimbabwe" , "group":"altro"}]}}; </script> </body>
i think should wrong in line:
if (!$('.itm').attr('checked' && ($(id).val()==''))) {
it might this:
if (!$('.itm').attr('checked') && ($(id).val()=='')) {
Comments
Post a Comment