Reputation: 27
I have a list of links to pdfs. Users can check a checkbox for each pdf, and then submitting the form will launch an email (using mailto:) with the items they have selected.
Everything works fine, except in the body of the email, the selected pdfs array are separated by a comma, so the comma is appearing in the email body.
Can anyone please help me get rid of the comma that separates them?
Tina
Upvotes: 0
Views: 606
Reputation: 18219
use join()
on the array to concatenate them into a string, you may speicfy which character to delimit.
e.g. selectedpdfs.join(' ')
will return a string delimited by a space.
see http://jsfiddle.net/qiao/HmWf3/1/ for a live demo
Upvotes: 0
Reputation: 79830
Update your script like below and let me know if it works,
$('#send-email').submit(function(){
var selectedpdfs = '';
$('#send-email input:checkbox:checked').each(function(i){
// All selected pdfs: gets link's text and link's url
selectedpdfs += $(this).prev().text() + '%0a' + $(this).prev().attr('href') + '%0a%0a'
});
//alert(selectedpdfs);
window.location.href = 'mailto:?subject=Materials&body='+selectedpdfs
return false;
});
Note: I modified selectedpdfs to a string object and changed it to string concatenation.
Array to String -> will return you a comma separated list of string.
Upvotes: 2