Question

I am new to jquery and want to accomplish the following.
1) Generate and show a form when a button is clicked

2) Have the user use checkboxes on that form to indicate who they want to send the email to

3) For every checked box in the dialog box, use cfmail to email said person (I can write this part)

Please see the start of my code below.

<script>
$(document).ready(function() {

    $("#notifyregs").click(function() {
        var initialDiv = this;
       // HELP - set the checked box values

        var reminderemails = $(this).data("reminderemails");
        var count = 0;

        $("#editForm").dialog({ width: 500, height: 'auto', maxHeight: 1000,
            buttons: {
                "Send Emails": function() {
                    var thisDialog = $(this);
                   // HELP - Loop through reminderemails and send each value to the function sendreminders
                    $.post("tsafunctions.cfc", {
                        method: 'sendreminders',
                    reminderemails: $("#reminderemails").val(), 
                        }, 
                    function() {
                        $("#message").show();
                        $("#message").text('You sent reminders to ' + count + ' athletes');
                        $(thisDialog).dialog("close");
                    });
                }
            }
        });
    });

});
</script>

The Form

  <div id="editForm" title="Notify Incomplete Registrations">
  Check who to send emails to:<br />
  <input type="checkbox" name="reminderemails" value="123456" checked="checked" />
  <input type="checkbox" name="reminderemails" value="234567" checked="checked" /></td>
</div>
Was it helpful?

Solution

Try this:

selectedEmails=jQuery('#editForm :checkbox:checked').serialize();

In your jQuery.post there is a data option for passing data:

$.post("tsafunctions.cfc", {data:selectedEmails, ...});

OTHER TIPS

Based on your code, it appears that you want to make a request to the $.post function for each selected checkbox. If you don't want to parse the serialized data, you would need something like this:

//--collect the checked input values and store in array
var reArr = [];
$('#editForm input:checked').each(function(){
   /*--
     pushes the value of each checkbox control that 
     is checked within the #editForm Div into and array
   --*/
  reArr.push($(this).val()); 
});

//--loop through the array and make your requests
for(var i=0; i < reArr.length; i++ ){
   /*--
    access each of the array elements using array syntax (e.g. reArr[i])
   --*/
   console.log(reArr[i]) 
   $.post("tsafunctions.cfc", {"reminderemails":reArr[i]} );
 }
 console.log(reArr);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top