I need to triger the autocomplete function by a condition

I need to triger the autocomplete function by a condition

 Hi....

 

                When I use Jquery autocomplete i have a doubt in it.

 

                I need to triger the autocomplete function by a condition. When I select the 1st  condition from dropdown list the Jquery autocomplete should triger.

                When I select the 2nd option the autocomplete should not works. This process should repeat for ever.

 

                I had used to options:

 

                                $("#Searchtype").change(function(events) {

         

            if ($("#Searchtype option:selected").val() == "Tags") {

              

                $('#tagName').autocomplete('<%=Url.Action("tags","company") %>', {

                    delay: 100,

                    minchars: 3

                });

 

                $('#tagName').result(function(e, d, f) {

                    $('#TagID').val(d[1]);

                });

 

            }

            else if ($("#Searchtype option:selected").val() == "Text") {

           

                $("#tagName").unautocomplete();

            }

 

 

        });    

 

 

                #Searchtype = is a dropdown list box where I need to select condition.

      #tagName  = is a textbox where autocomplete should appear.

 

 

 

      When I use  $("#tagName").unautocomplete(); it works for first time when the text option is selected.

 

      But when I select text option unautocomplete(); function triggers but after that no functions trigger for $("#tagName")text box.

 

 

      I had used $("#tagName").flushCache(); function also. But it not even stops the autocomplete option.

 

 

 

Please if any know the solution for this.

 

 

Thanks in Advance.

 

               

 

Thanks & Regards,

A.Kamalakannan