Solved

Combo boxes

Posted on 2000-02-22
3
141 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML page and JavaScript 2 86
SVG Star 4 34
Change month dropdown 5 32
Adding a Li to a UL after a specified Li contents 2 42
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

914 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

20 Experts available now in Live!

Get 1:1 Help Now