Page 1 of 1

Javascript: adding/removing values from txtbox from listbox

Posted: Sat Jun 18, 2011 3:28 pm
by cjkeane
hi everyone,

i'm new to javascript. i have the following code appending emails together together into a textbox when items are selected from a listbox. i have two issues.
1. the first selection passed to the emailcc textbox always appears as:
, johnsmith@home.ca
2. i'd like the ability to click on the listbox again to remove the email addresses selected from the textbox if email addresses in the list box are clicked a second time.

whats the best way to accomplish this? thanks.

<script type="text/javascript" language="JavaScript">
function Copy_listbox(){
document.emailaddresses.emailcc.value += ", " + document.emailaddresses.SelectEMailccListBox.value;
}
</script>

Re: Javascript: adding/removing values from txtbox from list

Posted: Sat Jun 18, 2011 5:35 pm
by McInfo
If the goal is to submit multiple email addresses in a form, try

Code: Select all

<select multiple name="emails[]">
With the multiple attribute, the user is able to select more than one option by holding the Shift or Ctrl key while clicking. The [] in the name attribute means that all values submitted with the name emails[] (all selected options) should be grouped together in an array named emails.

Also, see this example in the manual.