Changing hidden field if any checkbox is checked

Changing hidden field if any checkbox is checked

I've obviously got something wrong here. How do I pass a "interestsYes" or "interestsNo" to a hidden field based on whether any of eight checkboxes are checked? Here's what I have, which basically says, "If any checkbox is checked, set the hidden field "interestAny" to "Yes". If no checkboxes are checked, set the hidden field "interestAny" to "No".

  1. $(document).ready(function() {
  2. if ($("#clientForm input:clientInterest:checked").length > 0)
  3. {
  4. $('#interestAny').val($(this).val('Yes'));
  5. } else {
  6. $('#interestAny').val($(this).val('No'));
  7. }
  8. });

  9. In the form we have this hidden field:

  10. <input type="hidden" name="interestAny" value="">