Problem with Multiple selection from a Menu List and show into the text Area

liunx

Guest
Hello everyone. I am trying to select couple of itemsfrom a menu bar and those will be displayed in a restricted text area (one in each row) where user can only give input by selecting item from menu list). But I am having problem with selecting items. When I select the next one the first one appeared in the text area and so on. Please have a look of the following code. Any suggestion. <br />
<br />
<br />
<br />
<html><br />
<head><br />
<title><br />
</title><br />
</head><br />
<body><br />
<script><br />
function copythis(str)<br />
{<br />
document.myform.copied.value += str + '\n';<br />
}<br />
</script><br />
<br />
<form name='myform'><br />
<?php<br />
$Domain_Name[] = "Cricket";<br />
$Domain_Name[] = "Soccer";<br />
$Domain_Name[] = "Table Tennis";<br />
$Domain_Name[] = "Chess";<br />
?><br />
<br><br />
<br />
<select name = "InputDomainMenu[]" Multiple onclick="copythis(this.options[this.selectedIndex].value);"><br />
<br />
<?php<br />
foreach ($Domain_Name as $Existing_Item)<br />
print " <option value=\"$Existing_Item \">$Existing_Item</option>";<br />
?><br />
</select><br />
<br />
<br><br><br />
<br />
<textarea name = 'copied' rows = "20" cols = "45"></textarea><br />
<br />
</form><br />
<br />
</body><br />
<br />
</html><!--content--><select name = "InputDomainMenu[]" Multiple onclick="copythis(this.options[this.selectedIndex].value);"><br />
When you have multiple things selected, the selectedIndex is not valid. You have to step through each OPTION and check it's selected attribute. Something like:<br />
<select name="InputDomainMenu[]" Multiple onblur="copythis(this)"><br />
...<br />
<script><br />
function copythis(obj) {<br />
var txt = "";<br />
for (var i in obj.options)<br />
{if (obj.options.selected)<br />
{txt += obj.options.value;}<br />
}<br />
}<br />
</script>The onclick is not the event you want to use, either. That fires when you first drop down the menu, before you've selected anything. I don't think that the onblur will be much better. I think you should have some sort of button that lets the user say "ok, I'm done".<!--content-->
 
Back
Top