Solved

Combo boxes

Posted on 2000-02-22
3
142 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
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
xabi earned 100 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with a CSS in a page 2 30
How would I do a website like this? 5 52
Border and image sizing 5 17
How do I pull the base url for use in html links 7 22
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now