javascript - How to disable all items in select box when i am selecting 'ALL' item using select2 jquery -


i working in asp.net using select2 jquery. in select box have 10 items including 'all'. requirement when selected item , rest of items must disabled, when remove tag, whole item should enabled. http://ivaynberg.github.io/select2/ jquery written below.

 $(document).ready(function () {     $("#select1").select2({         placeholder: 'find , select books'       }).on("change", function (e) {            alert(e.val)     }); }); 

pls me????

html markup:

<html xmlns="http://www.w3.org/1999/xhtml"> <head id="header1" runat="server"> <title>jquery select2 plug-in</title> <script type="text/javascript"   src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <script type="text/javascript" src="d:/dotnet/its_google_chart_tabs_listbox/scripts/select2- 3.4.1/select2.js"></script> <link href="d:/dotnet/its_google_chart_tabs_listbox/scripts/select2-3.4.1/select2.css"  rel="stylesheet"/>   </head>  <body> <form runat="server"> <select id="select1" runat="server" datasourceid="ds1" datatextfield="emp_name" multiple="true" style="width:300px"/> <asp:sqldatasource id="ds1" runat="server" connectionstring="<%$ connectionstrings:constr %>" selectcommand="select top 10 * emp" />    </form> </body> <script type="text/javascript"> $(document).ready(function () {     $("#select1").select2({         placeholder: 'find , select books'        }).on("change", function (e) {          alert(e.val)     });  });   </script> </html>    c# code:   select1.items.insert(0, new listitem("all", "all")); 

rather disabling items on clicking all can select values .the code here :

$("#e1").select2(); $("#e1").on("change", function(e) {     var selected = e.val;     if ($.inarray("all", selected) !== -1) {         var id = "e1"         var element = $("#" + id);         var selected = [];         element.find("option").each(function(i, e) {             if($(e).attr("value")=="all")                 selected[selected.length] = $(e).attr("value");         });         element.select2("val", selected);     } }); 

and jsfiddle link http://jsfiddle.net/jeadr/734/ . hope helps ...

courtesy: @marcusasplund


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -