At the moment, my website displays a list of registered users in one column and their email addresses with checkboxes next to them in another column. Users can check the boxes and then click a submit button to generate a list of the selected emails separated by semicolons.
The problem I'm facing is that when the list is generated after hitting submit, the first email address has "undefined" right next to it. Instead of showing "[email protected]; [email protected]", it appears as "[email protected]; [email protected]".
Below is my jQuery code:
jQuery(document).ready(function() {
jQuery('#memberSubmit').click(function() {
var emailList;
jQuery('.email-members input:checked').each(function() {
var $this = jQuery(this);
emailList += $this.next('a').html() + "; ";
});
jQuery('.email-message').hide();
jQuery('.email-members').hide();
jQuery('.email-checks').hide();
jQuery('#memberSubmit').hide();
jQuery('.email-results a').attr('href', "mailto: " + emailList).fadeIn(2000);
jQuery('.email-results .email-list p').html(emailList).fadeIn(2000);
jQuery('.email-results h2').fadeIn(2000);
jQuery('.email-results p').fadeIn(2000);
jQuery('.email-list h2').fadeIn(2000);
});
});
I suspect the error lies in this line of code:
emailList += $this.next('a').html() + "; ";
. However, I'm not entirely sure. Any suggestions would be greatly appreciated!
Thank you!