/    Sign up×
Community /Pin to ProfileBookmark

Javascript function to omit "," for the last email address selected by check boxes

Hi,

I need some help here.

I am developing something similar to the email system using php.

Currently, I am writing something for the users to select the check boxes in order to select the recipients of the email.

This is (like the Yahoo! email) basically a pop up menu, with all the email addresses drawn from the database and check boxes for the users to select.

And similar to the Yahoo! email system, after the users made their selections and click on the select button, the pop up table will close and the selected email addresses will be instantly reflected in the mail browser page, in the to: textbox.

something like this:
to: [email][email protected][/email] , [email][email protected][/email] , [email][email protected][/email]

[COLOR=red]
I need a function to read all the checked boxes and place a “,” after each email address, which is achieved by the code below. But my challenge now is to omit the “,” for the last email address that is being selected
[/COLOR]

Can anyone advise please…

function updateaddr_bcc(listStr){

nAddr = document.getElementsByName(‘address’);
if (listStr!=”){
for (i=0; i<nAddr.length; i++)
{if (nAddr[i].checked == true){listStr += “,” + nAddr[i].value}}}

[COLOR=blue]
else{ // this is the part that requires changes
count=nAddr.length;
for (i=0; i<count; i++)
{if (nAddr[i].checked == true && ……){listStr += nAddr[i].value + “,”}
if (nAddr[i].checked == true && …….){listStr += nAddr[i].value }
}
}
[/COLOR]

opener.replyauthor.bcc_email.value = listStr;
self.close();
}

Can someone please advise on the approach to achieve this?

Any advise is most appreciated.

Thanks for reading.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@russellDec 23.2004 — after your for loop add this:<i>
</i>listStr = listStr.substr(0, listStr.length-1);
Copy linkTweet thisAlerts:
@JellybeanauthorDec 23.2004 — Hi Russell,

My code is woking now.

Thank you so much!

Have a Merry Christmas!
Copy linkTweet thisAlerts:
@russellDec 23.2004 — and Merry Christmas to you too.
×

Success!

Help @Jellybean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...