Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using msdropdown jquery. in this, it will filter the li string based on we type. but it search the li string which contains the given search text. search is based on following code:

var items = $("#" + childid + " li:Contains('" + sText + "')").show();

but i need that if i type letter N, it should jump to the list which li have the index of N.
For example, i have a list "apple,banana, cake,dog,elephant,orange,ball,cat,doll,egg"
if i type "e", now it will filter the list as "apple,cake,elephant,orange"

but I need a filter like: "elephant,egg" like this.

Thanks
Posted

Try to adapt from this example code:
XML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){

    var arr = [ "monkey", "lion", "egg", "tiger", "elephant" ];
    $("button").click(function(){
    $("div").empty();
        var list = "<ul>";

        $.each(arr, function(index, item) {
             var pattern = new RegExp("^"+ $("#txt").val() +".*");
            if (item.match(pattern)){
               list += "<li>"+item+"</li>";
            }
        });
        list += "</ul>";
        $("div").append(list);
    });

});
</script>
</head>
<body>
<input type="text" value="" id="txt">
<br>
<button type="button">Search</button>
<div></div>

</body>
</html>

Read more:
The 30 Minute Regex Tutorial[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900