Solved

Combo boxes

Posted on 2000-02-22
3
144 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
align Linkedin sign to the right page 5 55
Can't find PHP files on account that has WordPress 3 38
Create tabs to show divs 9 35
AJAX Wordpress Not Reading Variable 2 27
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

808 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