Reputation: 9575
All One Two three
My requirement is
Please help
Upvotes: 0
Views: 654
Reputation: 49291
This solution uses a cb class selector on the "child" textboxes. Another solution would be to select all those that don't have an id=all. It compares the length of the set of checked child checkboxes with the length of the set of all child checkboxes to determine if all should be checked.
<script type="text/javascript">
$(document).ready(function() {
$('#all').click(function() {
$('.cb').attr('checked', this.checked);
});
$('.cb').click(function() {
var allChecked = $('.cb:checked').length == $('.cb').length;
$('#all').attr('checked', allChecked);
});
});
</script>
<input type="checkbox" name="checkGroup" id="all" value="0" />All
<input type="checkbox" name="checkGroup" id="one" class="cb" value="1" />One
<input type="checkbox" name="checkGroup" id="two" class="cb" value="2" />Two
<input type="checkbox" name="checkGroup" id="three" class="cb" value="3" />Three
Upvotes: 0
Reputation: 187110
$(function(){
$("#all").click(function(){
$("input:checkbox[name='checkGroup']").attr("checked",$(this).attr("checked"));
});
$("input:checkbox[name='checkGroup']:not('#all')").click ( function(){
var totalCheckboxes = $("input:checkbox[name='checkGroup']:not('#all')").length;
var checkedCheckboxes = $("input:checkbox[name='checkGroup']:not('#all'):checked").length;
if ( totalCheckboxes === checkedCheckboxes )
{
$("#all").attr("checked" , true );
}
else
{
$("#all").attr("checked" , false );
}
});
});
Upvotes: 2
Reputation: 21771
What is your trying?
Let's try
<script language="JavaScript" type="text/javascript" src="jquery.js"></script>
<script language="Javascript" type="text/javascript">
$(document).ready(function() {
$("#toggle5").click(function(event){
$('input[@type=checkbox]').each( function() {
if($(this).val()==5)
this.checked = !this.checked;
});
});
});
</script>
<a href="#" id="toggle5">Toggle 5ve</a>
<form method="post" action="" style="margin:0px">
<input type="checkbox" name="a" value="1" id="" />
<input type="checkbox" name="b" value="2" id="" />
<input type="checkbox" name="c" value="3" id="" />
<input type="checkbox" name="d" value="4" id="" />
<input type="checkbox" name="e" value="5" id="" />
<input type="checkbox" name="f" value="5" id="" />
</form>
Upvotes: 0