I have a web page which has 6 checkboxes on it.
<input type="checkbox" name="chk1" id="chk1" class="chkbox"/>
<input type="checkbox" name="chk2" id="chk2" class="chkbox"/>
<input type="checkbox" name="chk3" id="chk3" class="chkbox"/>
<input type="checkbox" name="chk4" id="chk4" class="chkbox"/>
<input type="checkbox" name="chk5" id="chk5" class="chkbox"/>
<input type="checkbox" name="chk6" id="chk6" class="chkbox"/>
Using jquery how can I check to see if all of these 6 checkboxes are checked and if all 6 are checked check checkbox number 7:
<input type="checkbox" name="chk7" id="chk7" class="chkbox"/>
I have started to write the function but not sure if this is the best way to do this:
function AllSectionsChecked {
var isChecked1 = $('##chk1').attr('checked')?true:false;
var isChecked2 = $('##chk2').attr('checked')?true:false;
var isChecked3 = $('##chk3').attr('checked')?true:false;
var isChecked4 = $('##chk4').attr('checked')?true:false;
var isChecked5 = $('##chk5').attr('checked')?true:false;
var isChecked6 = $('##chk6').attr('checked')?true:false;
}
Any help would be appreciated. I am guessing its pretty much straight forward but just looking for the best way to accomplish this in jquery.
UPDATE:
*The ids and names are created dynaically and may not be in any order or scale so an id maybe chk51 and the next one maybe chk205, Appologies I should have put this in my original post *
Thankyou for your suggestions so far.
many thanks
Assuming the ID of the last checkbox should be
chk7and notchk5?DEMONSTRATION