Click to See Complete Forum and Search --> : Problem with selecting item from Menu and showing in a text box
I am having problem with this code. whenever I am selecting any item from list, it's showing undefined in the text box. So could you plese have a look and let me know what do do? Thank you.
<html>
<head>
<title>
</title>
</head>
<script>
function copythis(str)
{
document.myform.copied.value += str;
}
</script>
<form name='myform'>
<?php
$Domain_Name[] = Cricket;
$Domain_Name[] = Soccer;
$Domain_Name[] = TableTennis;
$Domain_Name[] = Chess;
?>
<br>
<input type='text' name='copied' value=''>
<select name = "InputDomainMenu[]" Multiple onchange="copythis(this.selectedvalue);">
<?php
foreach ($Domain_Name as $Existing_Item)
print "<option value='{$Existing_Item}'>{$Existing_Item}</option>";
?>
</form>
</html>
There are a few errors in that. Note items in bold and my comments
<html>
<head>
<title>
</title>
</head>
<script>
function copythis(str)
{
document.myform.copied.value += str;
}
</script>
<form name='myform'>
<?php
$Domain_Name[] = "Cricket"; //quotes needed around these values -- they are not constants.
$Domain_Name[] = "Soccer";
$Domain_Name[] = "TableTennis";
$Domain_Name[] = "Chess";
?>
<br>
<input type='text' name='copied' value=''>
<select name="InputDomainMenu[]" multiple="multiple" onchange="copythis(this.options[this.selectedIndex].value);">
<?php
foreach ($Domain_Name as $Existing_Item)
print "<option value='$Existing_Item'>$Existing_Item</option>";
?>
</select>
</form>
</html>
Thank you for oyur help. I solved the problem, but now it's showing textbax first and the right side of it I can see the menu list.
How can I put the menu list first and then below the text box. Thank you.
Move this line:
<input type='text' name='copied' value=''>
to below the closing </select>
Thnak you for your help again. Every thing is working perfectly. I am wondering about tha text box. How can I protect that text box so that user cannot type anything into it. He/She must have to select from the menu list and then it will be appeared in the text box.
Thank you.
<input type='text' name='copied' value='' readonly="readonly">
Man you are good. Tell you the truth I am a beginner. SO you can guess my knowledge.
One more question for you. Is there anyway user can delete any item form the text box but he/she cannot insert anything by typing.
Try something like this out:
<input type="text" name="copied" value="" readonly="readonly" onclick="this.value='';">
Thank you for your help. Please take a look of this code. I am trying to display one item each row in a text area. But I cannot seelct one item consecutively two times. COuld you please help me to sove this problem.
<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 onchange="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' readonly="readonly" rows = "20" cols = "45"></textarea>
</form>
</body>
</html>
That uses the onchange handler, which will only run when the selected item changes. If you want to be able to do it multiple times, you will have to use something that supports the onclick handler (a link, for example)
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>