I have 5 flags in the class check (with the name cb1, cb2, cb3, ...) and 5 corresponding text fields in the class text (with the name tf1, tf2, tf3, ...). When one or several checkboxes are checked, I want to count all the checked checkboxes and put the amount in the text fields that correspond when the button is clicked.
Example: If cb1 and cb3 are checked than tf1, and tf3 will have a value of 2.
So far I am counting all checked flags:
$(':button').click(function() {
total= $('.check:checked');
count=total.length;
});
But I cannot figure out how to get "count" in the corresponding text fields. Any help is appreciated!
PS I have different flags and text fields in different classes, so it is important that they refer to the class.
source
share