Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
I want to make autoserch where I add li tag to ul tag
My Code is
<pre lang="HTML">
 
                &lt;div class="row clearfix"&gt;
                   
                    &lt;div class="col-md-11"&gt;
                        &lt;div class="form-group"&gt;

                            <b>
                                &lt;asp:Label ID="lblTagRegisteredUsers" runat="server" Text="FPS"&gt;&lt;/asp:Label&gt;&nbsp;<i class="fa text-red">*</i></b>
                            &lt;div id="lblProcessingTagFPS" class="pull-right" style="display: none;" &gt;<i class="fa fa-refresh fa-spin"></i>&lt;/div&gt;
                            &lt;ul id="dvTag" runat="server" name="dvTag" &gt;&lt;/ul&gt;

                       <b></b>
                    &lt;/div&gt;
                  
                    
                &lt;/div&gt;
           </pre>


My javascript function is, for making li tag

<pre lang="Javascript">
        $('#dvTag').tagit({
            triggerKeys: ['comma', 'enter', 'space', 'semicolon'],
            placeholder: 'Enter FPS Code OR Name...',
            tagSource: function (request, response) {
                //alert("yes");
                var alloc = $('#ContentPlaceHolder1_ddlA :selected').text();
                var tehsil = $('#ContentPlaceHolder1_ddlT :selected').val();
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "../scm/Search_CS.ashx?act=ul&f=" + request.term + "&alloc=" + alloc + "&tehsil=" + tehsil,
                    data: "{}",
                    dataType: "json",
                    async: true,
                    beforeSend: function () {
                        $('#lblProcessingTagFPS').show();
                    },
                    complete: function (xhr, textStatus) {
                        $('#lblProcessingTagFPS').hide();
                    },
                    success: function (data) {
                        mydata = new Array();
                        for (var i = 0; i &lt; data.length; i++) {

                            mydata.push({

                                label: data[i].FPS_ShopName_EN,
                                value: data[i].FPSCode

                            });
                        }
                        //setup the search to search the label and the description
                        var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
                        response($.grep(mydata, function (value) {
                            return matcher.test(value.label) || matcher.test(value.desc);
                        }));
                    }
                });
            }
        });</pre>
When I add li tag it contains div and a tag.
Now I want to remove all li tag from ul tag in jquery on selection index change.
My jquery code is
<pre lang="Javascript">function RemoveList()
        {
            $('#dvTag').each(function () {
     var elem = $('#dvTag');
     if (elem.children().length &gt; 1) {                                 elem.children().remove();                                        

                                      }

                                  }
                                );

                            }</pre>
It is working but after removing li tag ,again I type text for autoserch,
method in Search_CS.ashx reteun suggested list but on gui ,it is not show list that is why i can select tag.


In Tagit function

JavaScript
return matcher.test(value.label);//this line is not working after removing li tag in RemoveList by elem.children().remove();
Posted
Updated 19-Jan-16 21:57pm
v10

Below is the simple method for clearing the li of the u
function RemoveList(){
    $("#ulelementID").html("");
}
 
Share this answer
 
Comments
Member 7909353 20-Jan-16 1:00am    
In li tag ,I have div tag and a tag.
$("#ulelementID").html(""); it is removing div and a tag only
Sri Nivas (Vasu) 20-Jan-16 1:31am    
What exactly you want to clear from <ul> tag?

Is this <ul> tag contain div?
Member 7909353 20-Jan-16 1:37am    
<ul> tag contains <li>
<div></div><a></a>
</li>
I want to remove all <li> tag from <ul> tag
Member 7909353 20-Jan-16 1:42am    
In Tagit funtion,return statement is not working, i think bcoz alert shows <li> tag
response($.grep(mydata, function (value) {
alert(data[0].FPS_ShopName_EN); //for check value, it is fine ,it shows value
return matcher.test(value.label);// I think this line is not working
}));
Member 7909353 20-Jan-16 1:57am    
In Tagit function,
return matcher.test(value.label);//this line is not working
JavaScript
RemoveList()
        $('#dvTagFPS').tagit("reset");

becoz i am using tagit.js library
 
Share this answer
 

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