Click here to Skip to main content
15,908,775 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to insert searched record in autocomplete dropdown.

For Ex. if i am having array of cars which has value

CAR1 , CAR2 And CAR3 , so when i searched CAR4 Then this CAR4 Value insert into that exisitng autocomplete dropdown.

Thanks In advance.
viral

What I have tried:

I have tried simple autocomplete dropdown example. but i am not able to find solution for above problem.
Posted
Updated 22-Feb-18 23:10pm
Comments
ZurdoDev 15-Feb-18 13:48pm    
Write code to do it. But since we can't see any of your controls I'm not sure we can tell you much more.

1 solution

Hi ,

here is the solution:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

    <script type="text/javascript">

        $(document).ready(function() {

            var cars = ['CAR1', 'CAR2', 'CAR3'];

            $('[id$=txtAutocompCars]').autocomplete({
                source: cars.filter(onlyUnique)
            });

            $('[id$=txtAutocompCars]').focusout(function() {
                //alert("changed");
                var newcar = $('[id$=txtAutocompCars]').val();
                cars.push(newcar);

                //  jQuery.each(cars, function(i, val) {
                //  alert("Mine is " + val + ".");
                //  });

                //Recall the autocomplete function;
                $('[id$=txtAutocompCars]').autocomplete({
                    source: cars.filter(onlyUnique)
                });
            });

        });


        function onlyUnique(value, index, self) {
            return self.indexOf(value) === index;
        }
       
        
    </script>


html part:

<input name="cars" id="txtAutocompCars" type="text" />
 
Share this answer
 
Comments
ViralPatva 23-Feb-18 8:47am    
Thanks Sarita.

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