ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Limit ASP.Net ListBox item selection using JavaScript and jQuery<p>Hi <a class="username" rel="anirudhp">anirudhp</a>,</p> <p>Will you please let me know for multiple selection which plugin you are using ?</p> <p>Please share your code.</p>https://www.aspforums.net:443/Threads/101604/Limit-ASPNet-ListBox-item-selection-using-JavaScript-and-jQuery/https://www.aspforums.net:443/Threads/101604/Limit-ASPNet-ListBox-item-selection-using-JavaScript-and-jQuery/Fri, 14 Sep 2018 05:35:01 GMTLimit ASP.Net ListBox item selection using JavaScript and jQuery<p>&nbsp;</p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; language=&#34;javascript&#34;&gt; function onClientSelectedIndexChangingHandler(source, arguments) { var listbox = document.getElementById(&#39;&lt;%=ddlCOMMISION.ClientID%&gt;&#39;); var selectedCount = 0; for (var index = 0; index &lt; listbox.options.length; index++) { if (listbox.options[index].selected) selectedCount += 1; } if (selectedCount &lt; 4) arguments.IsValid = true; else arguments.IsValid = false; } &lt;/script&gt; &lt;asp:ListBox ID=&#34;ddlCOMMISION&#34; SelectionMode=&#34;Multiple&#34; CausesValidation=&#34;True&#34; Height=&#34;50px&#34; runat=&#34;server&#34;&gt; &lt;asp:ListItem&gt;--Select--&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;% ON BASIC RATE&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;% ON NETT ORDER AMT&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Rs PER KG&lt;/asp:ListItem&gt; &lt;/asp:ListBox&gt; &lt;asp:CustomValidator ID=&#34;CustomValidator1&#34; runat=&#34;server&#34; ErrorMessage=&#34;Maximum Countries you can select are 5&#34; ClientValidationFunction=&#34;onClientSelectedIndexChangingHandler&#34;&gt;&lt;/asp:CustomValidator&gt; </pre> <p>here the code i used</p>https://www.aspforums.net:443/Threads/101604/Limit-ASPNet-ListBox-item-selection-using-JavaScript-and-jQuery/https://www.aspforums.net:443/Threads/101604/Limit-ASPNet-ListBox-item-selection-using-JavaScript-and-jQuery/Fri, 14 Sep 2018 06:02:14 GMTLimit ASP.Net ListBox item selection using JavaScript and jQuery<p>Hi <a class="username" rel="anirudhp"> anirudhp</a>,</p> <p>Refer the below code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:ListBox ID=&#34;ddlCOMMISION&#34; SelectionMode=&#34;Multiple&#34; CausesValidation=&#34;True&#34; Height=&#34;50px&#34; runat=&#34;server&#34;&gt; &lt;asp:ListItem&gt;% ON BASIC RATE&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;% ON NETT ORDER AMT&lt;/asp:ListItem&gt; &lt;asp:ListItem&gt;Rs PER KG&lt;/asp:ListItem&gt; &lt;/asp:ListBox&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#39;[id*=ddlCOMMISION]&#39;).on(&#39;change&#39;, function () { var selectedCount = 0; $(&#39;[id*=ddlCOMMISION] option&#39;).each(function () { if ($(this).is(&#39;:selected&#39;)) { selectedCount++; } if (selectedCount &gt; 2) { alert(&#34;you can select max 2 of items&#34;); $(this).removeAttr(&#34;selected&#34;); } }); }); }); &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://imgur.com/kUOL6uZ.gif" alt="" width="286" height="192" /></p>https://www.aspforums.net:443/Threads/101604/Limit-ASPNet-ListBox-item-selection-using-JavaScript-and-jQuery/https://www.aspforums.net:443/Threads/101604/Limit-ASPNet-ListBox-item-selection-using-JavaScript-and-jQuery/Fri, 14 Sep 2018 07:15:37 GMT