Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Copy selected values from list into input field



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
ajoo



Joined: 26 Jun 2008
Posts: 5

PostPosted: Mon Jul 07, 2008 8:22 pm    Post subject: Copy selected values from list into input field Reply with quote

Hi,
I need to write a java script: Here is what it should do, when user will click on the add button it will copy the add the selected value into input field seperated by comma(,). If the input field already has some name the selected name(s) will be added to the existing value of input field
Thanks

<html>
<head>
<title>Test</title>

</head>

<body>

<tr>
<td><strong>name</strong></td>
<td colspan="3"><input type="text" size="50" name="fName" value=""/></td>

<td colspan="3">
<INPUT TYPE=BUTTON VALUE="Add &lt;&lt" ONCLICK="copySelectedOptions('UserList')">
</td>
<td>
<SELECT MULTIPLE="MULTIPLE" NAME="UserList" SIZE="5" WIDTH=100 id="UserList">
<OPTION value="abrahast">abrahast</OPTION>
<OPTION value="abreura">abreura</OPTION>
<OPTION value="chris">chris</OPTION>
<OPTION value="john">john</OPTION>
<OPTION value="Ravi Tandon">Ravi Tandon</OPTION>

</SELECT>

</td>
</tr>
<br>
<br>
<br>
<tr>
<td>
<input type="button" name="B2" value="Save" onClick="test()">

</td>
</tr>
</body>
</html>
Back to top
View user's profile Send private message Yahoo Messenger
rangana
500+ Club


Joined: 27 Feb 2008
Posts: 563
Location: Cebu City Philippines

PostPosted: Tue Jul 08, 2008 3:27 am    Post subject: Re: Copy selected values from list into input field Reply with quote

Code:

<html>
<head>
<title>Test</title>
<script type="text/javascript">
window.onload=function()
{
document.getElementById('rangTrig').onclick=function()
   {
   var show=document.getElementById('rangShow'),
   opt=document.getElementById('UserList');
   if(show.value=='')show.value=opt.value;
   else show.value+=', '+opt.value;
   }
}
</script>
</head>

<body>

<tr>
<td><strong>name</strong></td>
<td colspan="3"><input type="text" size="50" name="fName" value="" id="rangShow"/></td>

<td colspan="3">
<INPUT TYPE=BUTTON VALUE="Add &lt;&lt" id="rangTrig">
</td>
<td>
<SELECT MULTIPLE="MULTIPLE" NAME="UserList" SIZE="5" WIDTH=100 id="UserList">
<OPTION value="abrahast">abrahast</OPTION>
<OPTION value="abreura">abreura</OPTION>
<OPTION value="chris">chris</OPTION>
<OPTION value="john">john</OPTION>
<OPTION value="Ravi Tandon">Ravi Tandon</OPTION>

</SELECT>

</td>
</tr>
<br>
<br>
<br>
<tr>
<td>
<input type="button" name="B2" value="Save" onClick="test()">

</td>
</tr>
</body>
</html>
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap