Solved

Combo boxes

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article discusses four methods for overlaying images in a container on a web 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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

706 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

17 Experts available now in Live!

Get 1:1 Help Now