/    Sign up×
Community /Pin to ProfileBookmark

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.

[code=php]

<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>

[/code]

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@pyroJul 18.2003 — There are a few errors in that. Note items in [b]bold[/b] and my comments

[code=php]<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([b]this.options[this.selectedIndex].value);[/b]">
<?php

foreach ($Domain_Name as $Existing_Item)

print "<option value='$Existing_Item'>$Existing_Item</option>";

?>

[b]</select>[/b]
</form>
</html> [/code]
Copy linkTweet thisAlerts:
@szmsauthorJul 18.2003 — 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.
Copy linkTweet thisAlerts:
@pyroJul 18.2003 — Move this line:

<input type='text' name='copied' value=''>

to below the closing </select>
Copy linkTweet thisAlerts:
@szmsauthorJul 18.2003 — 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.
Copy linkTweet thisAlerts:
@pyroJul 18.2003 — <input type='text' name='copied' value='' readonly="readonly">
Copy linkTweet thisAlerts:
@szmsauthorJul 18.2003 — 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.
Copy linkTweet thisAlerts:
@pyroJul 18.2003 — Try something like this out:

<input type="text" name="copied" value="" readonly="readonly" onclick="this.value='';">
Copy linkTweet thisAlerts:
@szmsauthorJul 18.2003 — 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.

[code=php]
<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>

[/code]
Copy linkTweet thisAlerts:
@pyroJul 18.2003 — 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)
Copy linkTweet thisAlerts:
@szmsauthorJul 18.2003 — 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.


[code=php]
<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>

[/code]
×

Success!

Help @szms spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...