473,799 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying Selectbox options to another selectbox

I have a form named 'choiceForm' and 2 select boxes named 'available'
and 'move'. I give users the ability of copying options (not moving)
from available to move with the code below. I would like to create a
button which copies all options from available to move but not sure how
to do this. Thanks for any help.

function moveOver()
{
var boxLength = document.choice Form.move.lengt h;
var selectedItem = document.choice Form.available. selectedIndex;
var selectedText =
document.choice Form.available. options[selectedItem].text;
var selectedValue =
document.choice Form.available. options[selectedItem].value;

var i;
var isNew = true;

if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choice Form.move.optio ns[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selected Text, selectedValue, false, false);
document.choice Form.move.optio ns[boxLength] = newoption;
}
document.choice Form.available. selectedIndex=-1;
updateList(docu ment.getElement ById('move'),
document.getEle mentById('newLi st'));
}

Nov 29 '06 #1
2 2734
Please disregard this question. I worked it out. Thanks.
shankwheat wrote:
I have a form named 'choiceForm' and 2 select boxes named 'available'
and 'move'. I give users the ability of copying options (not moving)
from available to move with the code below. I would like to create a
button which copies all options from available to move but not sure how
to do this. Thanks for any help.

function moveOver()
{
var boxLength = document.choice Form.move.lengt h;
var selectedItem = document.choice Form.available. selectedIndex;
var selectedText =
document.choice Form.available. options[selectedItem].text;
var selectedValue =
document.choice Form.available. options[selectedItem].value;

var i;
var isNew = true;

if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choice Form.move.optio ns[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selected Text, selectedValue, false, false);
document.choice Form.move.optio ns[boxLength] = newoption;
}
document.choice Form.available. selectedIndex=-1;
updateList(docu ment.getElement ById('move'),
document.getEle mentById('newLi st'));
}
Nov 29 '06 #2
ASM
shankwheat a écrit :
I have a form named 'choiceForm' and 2 select boxes named 'available'
and 'move'. I give users the ability of copying options (not moving)
from available to move with the code below. I would like to create a
button which copies all options from available to move but not sure how
to do this. Thanks for any help.
<script type="text/javascript">

function selectMove()
{
var from = document.choice Form.available;
var k = from.selectedIn dex
var selectedText = from.options[k].text;
var selectedValue = from.options[k].value;

var to = document.choice Form.move;

// to do not copy same option several times
var OK = true
for(var i=0; i<to.length; i++)
if(to[i].value==selecte dValue) OK = false;

if(OK)
to[to.length] = new Option(selected Text, selectedValue);
else
alert('option already copied');
}

</script>

<form name="choiceFor m">

<select name="available " onchange="selec tMove()">
<option value="a">A
<option value="b">B
<option value="c">C
<option value="d">D
<option value="e">E
<option value="f">F
</select>

<select name="move"
onchange="var k=this.selected Index;
alert(this[k].value+' '+this[k].text);">
</select>
</form>


--
Stephane Moriaux et son moins vieux Mac déjà dépassé
Stephane Moriaux and his less old Mac already out of date
Nov 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3673
by: Tole | last post by:
hi all, i've got a selcetbox (multiple) which is filled by javascript. only problem is that i have aprox 1000 options to add to that select, and that adding lasts for 5-6 seconds. Even select.length = 0 (on filled element) lasts for few seconds. ok. i have large amount of data to preload, and i also do some operations on that data, but it's all very fast. so i thought it must be some IE rendering issue, and i tried to set...
6
2233
by: Piotr Pietrowski | last post by:
Hello everybody, I have a *big* problem. I thought its not that big problem for you professionals... Anyway, I have a begin date which has 3 dropdown boxes (day/Month/Year). The same for the end date. So if somebody selects the begin date 13.12.2004 and the end date 19.12.2004
7
1980
by: Erwin Moller | last post by:
Hi, situation: I have a long list of options in multiple selectbox. The selectbox gets a scrollbar in that situation. Does anybody know if it is possible to scroll through the options with javascript? eg: moving the to the first selected option??
1
1837
by: shankwheat | last post by:
I've been using this little script to change the <a href=""></a> value of a link which works well. <script language="javascript" type="text/javascript"> function ordering(sorder) { var link = document.getElementById("mylink").href = "http://www.mysite.com?Option="+sorder; } </script>
4
1750
by: shankwheat | last post by:
I'm passing a string like 'Div3,Div4' to use as options in a selectbox but I need the text the user sees in the box different from the values. My code populates the values in the selectbox correctly but not the text. Thanks Desired end result: <select id="selectBox" multiple="multiple" size="4"> <option value="Div3">About the Company</option> <option value="Div1">Ratings</option>
4
3777
by: evanburen | last post by:
I have a bi-dimensional array that looks like this. I could split this up any I need to if there is a better method. {1,COMS}{2,IBM}{3,F} I want to use this array to populate a selectbox. The numeric value is the option value and the text is the text I want the user to see. I'm not sure what to do with the array once I get the data back and populate my selectbox.
1
1967
by: giloosh | last post by:
i would like to dynamically output such a selectbox below using php and mysql: <select> <option< 100 </option> <option100 to 150 </option> <option150 to 200 </option> <option200 to 250 </option> <option250 to 300</option> <option 300 </option> </select>
4
1425
by: ramchml | last post by:
i have two select boxes.based on the selected value in one select box it show the maximum options in the other select box in next page.i used javascript onclick function.for first time it shows correct options in the second select box if i go back and change the value in the 1st select box it shows me the previous value in the 2nd select box,the value not get changed.it is happening only in opera9 all the other browsers its working fine.it seems...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.