views:

33

answers:

0

I'm working on a form for new students planning to attend a university and have checkboxes beneath fields such as Father Personal E-Mail, Father Business, Mother Personal, Mother Business, etc.

I've been using code that can send to one address at a time,

if ($('#sendFatherPersonalEMail:checked').val() !== null) { //Father Personal
    $(function() {
 $("#father_eMail").change(function() {
   var newContactEmail = $(this).val();
   $("#cc").val(newContactEmail);
   });
  });
}

if ($('#sendFatherBusEMail:checked').val() !== null) { //Father Business
    $(function() {
 $("#father_busEMail").change(function() {
   var newContactEmail = $(this).val();
   $("#cc").val(newContactEmail);
   });
  });
}

But want it to send multiple e-mails at once. Would writing these fields to a string and passing that work? The following is pseudo javascript...

var emails="";
if ($('#sendFatherPersonalEMail:checked').val() !== null) { //Father Personal
    emails += "#father_eMail";
}
if ($('#sendFatherBusEMail:checked').val() !== null) { //Father Business
    emails += ", #father_busEMail";
}
if ($('#sendMotherPersonalEMail:checked').val() !== null) { //Mother Personal
    emails += ", #mother_eMail";
}
if ($('#sendMotherBusEMail:checked').val() !== null) { //Mother Business
    emails += ", #mother_busEMail";
}

$(function() {
 $(emails).change(function() {
   var newContactEmail = $(this).val();
   $("#cc").val(newContactEmail);
   });
  });

Thanks for any help you can give!