jimdgar2
asked on
Javascript needed to add multiple selections to a text area
I have a drop-down box with a list of items, user selects from that list, clicks on a Submit button
and the item selected is appended to a text area. The following code works OK for a single list item,
but I'd like to allow the user to select multiple items (ctrl-click or shift-click) to add multiple items.
How can I modify my javascript code to do this?
function add_users() {
if (document.getElementById(' to_text'). value.leng th > 0)
document.getElementById('t o_text').v alue += ',';
document.getElementById('t o_text').v alue += document.getElementById("t o_select") .options[d ocument.ge tElementBy Id("to_sel ect").sele ctedIndex] .value;
};
<select id="to_select" size="5" multiple="multiple" name="add_tos[]">
<? // php code here to fetch items from database and loop
echo '<option>' . $row['firstname'] . ' ' . $row['lastname'] . ' <' . $row['email'] . '></option>';
?>
</select>
<input id="add_button" type="button" value="Add" onClick="add_users();"/>
and the item selected is appended to a text area. The following code works OK for a single list item,
but I'd like to allow the user to select multiple items (ctrl-click or shift-click) to add multiple items.
How can I modify my javascript code to do this?
function add_users() {
if (document.getElementById('
document.getElementById('t
document.getElementById('t
};
<select id="to_select" size="5" multiple="multiple" name="add_tos[]">
<? // php code here to fetch items from database and loop
echo '<option>' . $row['firstname'] . ' ' . $row['lastname'] . ' <' . $row['email'] . '></option>';
?>
</select>
<input id="add_button" type="button" value="Add" onClick="add_users();"/>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER