Click to See Complete Forum and Search --> : Problem with Multiple selection from a Menu List and show into the text Area


szms
07-18-2003, 02:45 PM
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.



<html>
<head>
<title>
</title>
</head>
<body>
<script>
function copythis(str)
{
document.myform.copied.value += str + '\n';
}
</script>

<form name='myform'>
<?php
$Domain_Name[] = "Cricket";
$Domain_Name[] = "Soccer";
$Domain_Name[] = "Table Tennis";
$Domain_Name[] = "Chess";
?>
<br>

<select name = "InputDomainMenu[]" Multiple onclick="copythis(this.options[this.selectedIndex].value);">

<?php
foreach ($Domain_Name as $Existing_Item)
print " <option value=\"$Existing_Item \">$Existing_Item</option>";
?>
</select>

<br><br>

<textarea name = 'copied' rows = "20" cols = "45"></textarea>

</form>

</body>

</html>

gil davis
07-19-2003, 01:02 PM
<select name = "InputDomainMenu[]" Multiple onclick="copythis(this.options[this.selectedIndex].value);">
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:
<select name="InputDomainMenu[]" Multiple onblur="copythis(this)">
...
<script>
function copythis(obj) {
var txt = "";
for (var i in obj.options)
{if (obj.options[i].selected)
{txt += obj.options[i].value;}
}
}
</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".