?
Solved

Combo boxes

Posted on 2000-02-22
3
Medium Priority
?
147 Views
Last Modified: 2010-04-09
I have two multiple select dropdown lists on my page. On clicking a button I want to populate one list with the values selected from the other. Is this possible? If so, how?
0
Comment
Question by:wariar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
xabi earned 400 total points
ID: 2546385
Hi there:

Here goes my code to do this:

----------- 8< ---------- 8< ----
<html>
<head>
<script language="JavaScript">
<!--
function del_option(object,indice) {
 object.options[indice] = null;
}
function add_option(object,tmp_txt,tmp_value) {
 object.length++
 object.options[object.length-1].value = tmp_value
 object.options[object.length-1].text = tmp_txt
}
function copy_object(object_origen,object_destino) {
 for (var i=0, l=object_origen.options.length;i<l;i++) {
  if (object_origen.options[i].selected) {
   add_option(object_destino,object_origen.options[i].text,object_origen.options[i].value);
  }
 }
 for (var i=object_origen.options.length-1;i>-1;i--) {
  if (object_origen.options[i].selected) {
   del_option(object_origen,i)
  }
 }
}
function copy_all(object_origen,object_destino) {
 for (var i=0, l=object_origen.options.length;i<l;i++) {
  add_option(object_destino,object_origen.options[i].text,object_origen.options[i].value);
 }
 for (var i=object_origen.options.length-1;i>-1;i--) {
  del_option(object_origen,i);
 }
}
function init() {
 document.myform.myselect2.length = 0
}
//-->
</script>
</head>
<body onload="init()">
<form name="myform">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="center">My select 1:<br>
<select name="myselect1" size="10" multiple>
 <option value="option1">option1</option>
 <option value="option2">option2</option>
 <option value="option3">option3</option>
 <option value="option4">option4</option>
 <option value="option5">option5</option>
 <option value="option6">option6</option>
</select></td>
<td valign="middle" align="center">
<input type="button" value="&lt;&lt; Add all" onclick="copy_all(document.myform.myselect2,document.myform.myselect1)"><br><br>
<input type="button" value="&lt; Add" onclick="copy_object(document.myform.myselect2,document.myform.myselect1)"><br><br>
<input type="button" value="Del &gt;" onclick="copy_object(document.myform.myselect1,document.myform.myselect2)"><br><br>
<input type="button" value="Dell all &gt;&gt;" onclick="copy_all(document.myform.myselect1,document.myform.myselect2)">
</td>
<td align="center">My select 2:<br>
<select name="myselect2" size="10" multiple > 
 <option>---------------------------------------</option>
</select></td>
</tr>
</table>
</form>
</body>
</html>
--------- 8< -------- 8< --------
0
 

Author Comment

by:wariar
ID: 2546678
Exactly what I was looking for. Thanks again!
0
 
LVL 8

Expert Comment

by:xabi
ID: 2546762
Nice to help you.

Xabi
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question