Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am using three input whose type=checkbox in my design, now the check boxes are like this
All
1
2
All is checked by default. What i want is that when i select either 1 or 2 i want the "All" option to be unchecked.

My HtMl code:
XML
<li>
                           <h5 class="booking-filters-title">Abc</h5>
                           <div class="checkbox">
                               <label>
                                   <input id="chkAny"  class="i-check "   runat="server" type="checkbox" />All
                               </label>
                           </div>
                           <div class="checkbox">
                               <label>
                                   <input id="chkOne"   class="i-check" runat="server" type="checkbox" />1
                               </label>
                           </div>
                           <div class="checkbox">
                               <label>
                                   <input id="chkTwo"   class="i-check"  runat="server" type="checkbox" />2
                               </label>
                           </div>
                       </li>


I am using Bootstrap and I want it to be done via java script.

Regards
Syed
Posted
Comments
Kornfeld Eliyahu Peter 26-Nov-14 2:35am    
What have you tried?

1 solution

It's actually a simple solution, next time think through the problem and attempt something first and you will discover it's not that complicated! This should work

XML
<li>
   <h5 class="booking-filters-title">Abc</h5>
   <div class="checkbox">
       <label>
           <input id="chkAny"  class="i-check "   runat="server" type="checkbox" checked/>All
       </label>
   </div>
   <div class="checkbox">
       <label>
           <input id="chkOne" onclick="chkMe();"  class="i-check" runat="server" type="checkbox" checked/>1
       </label>
   </div>
   <div class="checkbox">
       <label>
           <input id="chkTwo" onclick="chkMe();"   class="i-check"  runat="server" type="checkbox" checked/>2
       </label>
   </div>
</li>
<script>
    function chkMe()
    {
        if(document.getElementById("chkOne").checked == true && document.getElementById("chkTwo").checked == true)
            document.getElementById("chkAny").checked = true;
        else
            document.getElementById("chkAny").checked = false;
    }
</script>
 
Share this answer
 
Comments
Syed.net 3-Dec-14 8:56am    
Hey bro thanks for the suggestion, but you see the solution was not that simple how you suggested.Anyways thanks.
Oso Oluwafemi Ebenezer 3-Dec-14 8:59am    
You can mark the solution as the answer if it solves the problem!

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