I have several checkboxes on my page. If the user clicks on the first checkbox that says 1, I want all other check boxes to be checked automatically. Below is my code:
“
@for (var i = 1; i <= 10; i++)
{
<input onclick="checkAll" name="AreChecked" class="chkTask" type="checkbox" value="@i" /> @i
}
</div>``
This is the output of the checkboxes:
If the first checkbox that says 1 is checked then I want other checkboxes 2,3,4,5,6,7,8,9,10 to be checked. I don’t have numbers for my checkboxes, I just have characters like, but I am displaying numbers in my code for the simplicity purposes.
This is what I tried:
$("#1").click(function(){ $('input:checkbox').not(this).prop('checked', this.checked); });
3
Answers
Here is the minimal example, you can cater it to your needs.
I don’t know how to do it with jquery, I have done it this way
Try this:
The if statement checks if the first checkbox is clicked – if true, then check all other checkboxes that are not the first checkbox.