KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a checkbox select all issue. I have multiple checkbox that can be triggered by a master one. If the master one is check then you can select any checkbox (which this works). Now my problem is when i check "none" all of them are gone even the master What I need is not to unchecked the master. I can have as many as checkbox as I want. Is there a solution to do this without putting an ID on each or automatically uncheck all checkbox and not the master one? here is my code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#checkAll').click(function() { if(!$('#master').is(':checked')) { return; } $('input[type="checkbox"]').attr('checked', true); }); $('#checkNone').click(function() { $('input[type="checkbox"]').attr('checked', false); }); $('#master').click(function() { if($('#master').is(':checked')) { return; } $('input[type="checkbox"]').attr('checked', false); }); $('input[type="checkbox"]').click(function() { if(!$('#master').is(':checked')) { $(this).attr('checked', false); } }); }); </script> </head> <input type="checkbox" value="master" id="master">master <span id="checkAll">All</span> <span id="checkNone">None</span> <input type="checkbox" value="1" id="c1">1 <input type="checkbox" value="2" id="c2">2 <input type="checkbox" value="3" id="c3">3 <input type="checkbox" value="4" id="c4">4 <input type="checkbox" value="5" id="c5">5
Tags (comma-separated)
Save Edits
Cancel