Jquery - Loop through Checkboxes and Multiple elements
- by Vincent
All,
I have a set of elements like this in a form:
<input type="checkbox" name="chk[140]">
<input type="hidden" value="3" name="ctcount[140]">
<input type="hidden" value="Apples" name="catname[140]">
<input type="checkbox" name="chk[142]">
<input type="hidden" value="20" name="ctcount[142]">
<input type="hidden" value="Bananas" name="catname[142]">
<input type="checkbox" name="chk[144]">
<input type="hidden" value="200" name="ctcount[144]">
<input type="hidden" value="Strawberries" name="catname[144]">
<input type="checkbox" name="chk[145]">
<input type="hidden" value="0" name="ctcount[145]">
<input type="hidden" value="Carrots" name="catname[145]">
When a user clicks a button, I want the Javascript to:
1. Loop through all the checkboxes
2. For all the checked checkboxes,
2a. Get ctcount value
2b. Get catname value
2c. If ctcount value > 50, alert a message saying "Unable to add item
as max limit for 'catname' has reached.
2d. Break the loop after it encountered first ctcount value that is
greater than 50.
I am new to JQuery..have the following code so far:
var checklimit = 50;
$('#frmTest input:checkbox:checked').each(function(i) {
alert(this.value);
});
How do I do this using JQuery?
Thanks