1

I have a autocomplete textbox. When am typing, the suggested list will shows. My code is given below,

$('#state').keyup(function(){
    $('#state_sugg').slideDown('fast');
    var val = $(this).val().toLowerCase(); 
    $('#state_sugg span').hide();
    var trs = $('#state_sugg span').filter(function(d){
        return $(this).text().toLowerCase().indexOf(val) != -1;
    });
    trs.show();   
});

The above code is working fine.

Now the result is, when am typing i if any string having letter i will be displayed. ie, if am typing i the result will be pondicherry, tamil nadu etc.

But i want the result as, if am typing ke the result should be kerala. ie, the string starts with the letter am typing should be displayed.

For that how to edit the above code. I have tried a lot.

Jithin Varghese
  • 2,018
  • 3
  • 29
  • 56

0 Answers0