0

I am trying to send each member email generate from the php if condition to an input text. The selection works well however, the problem I have is to find a way if multiple checkboxes are selected the emails sums spacing them with a coma. Right now what I have is that if I check multiple checkboxes the last email selected replaces the old one. Any Idea how Could I do this? Also if just one email is selected no coma have to be added and if the checkbox is unchecked the email is removed.

<?php if ( bp_has_members( "search_terms={$_POST['category']}")) : ?>
    <?php while ( bp_members() ) : bp_the_member(); ?>

           <table border="1" >          
            <tr>
             <td style="width:30px;">
              <input class="select_email" type="checkbox" name="get_email" value="<?php bp_member_user_email('type=user_email') ?>"/>
             </td>
             <td>
              <?php bp_member_user_email('type=user_email') ?>
             </td>
            </tr>
            </table>

    <?php endwhile; ?>
    <?php endif; ?>

Jquery

$(document).ready(function(){
    $(".select_email").click(function(){
       var select_check = $(this);
       var select_email = $(this).parent().find(".select_email").val();
       //var sum_email = select_email + ", " + select_email;
       if ( select_check.is(':checked') ) {
            // Do stuff
            alert(select_email + "   added");
            $("#my_email_to_id").val(sum_email);    
        }else {
            alert(select_email + "   removed");
        }
    });
});
2
  • I think the name of your inputs prevent you to achieve what you want i let you check here for more information Commented Apr 6, 2015 at 16:49
  • Thanks Jordan.. Not sure how to do this with foreach.. I was trying to achieve this in js Commented Apr 6, 2015 at 17:05

1 Answer 1

0
<?php if ( bp_has_members( "search_terms={$_POST['category']}")) : ?>
    <?php while ( bp_members() ) : bp_the_member(); ?>

           <table border="1" >          
            <tr>
             <td style="width:30px;">
              <input class="select_email" type="checkbox" name="get_email[]" value="<?php bp_member_user_email('type=user_email') ?>"/>
             </td>
             <td>
              <?php bp_member_user_email('type=user_email') ?>
             </td>
            </tr>
            </table>

    <?php endwhile; ?>
    <?php endif; ?>

Jquery
$(document).ready(function(){
    $(".select_email").click(function(){
       var val = $(':checkbox:checked').map(function(){ return this.value; }).toArray().join(', ');
          alert(val);
          $("#my_email_to_id").val(sum_email);
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.