Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Copying Selectbox options to another selectbox

Reply
Thread Tools

Copying Selectbox options to another selectbox

 
 
shankwheat
Guest
Posts: n/a
 
      11-29-2006
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.choiceForm.move.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText =
document.choiceForm.available.options[selectedItem].text;
var selectedValue =
document.choiceForm.available.options[selectedItem].value;

var i;
var isNew = true;

if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.move.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.move.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
updateList(document.getElementById('move'),
document.getElementById('newList'));
}

 
Reply With Quote
 
 
 
 
shankwheat
Guest
Posts: n/a
 
      11-29-2006
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.choiceForm.move.length;
> var selectedItem = document.choiceForm.available.selectedIndex;
> var selectedText =
> document.choiceForm.available.options[selectedItem].text;
> var selectedValue =
> document.choiceForm.available.options[selectedItem].value;
>
> var i;
> var isNew = true;
>
> if (boxLength != 0) {
> for (i = 0; i < boxLength; i++) {
> thisitem = document.choiceForm.move.options[i].text;
> if (thisitem == selectedText) {
> isNew = false;
> break;
> }
> }
> }
> if (isNew) {
> newoption = new Option(selectedText, selectedValue, false, false);
> document.choiceForm.move.options[boxLength] = newoption;
> }
> document.choiceForm.available.selectedIndex=-1;
> updateList(document.getElementById('move'),
> document.getElementById('newList'));
> }


 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      11-29-2006
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.choiceForm.available;
var k = from.selectedIndex
var selectedText = from.options[k].text;
var selectedValue = from.options[k].value;

var to = document.choiceForm.move;

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

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

</script>

<form name="choiceForm">

<select name="available" onchange="selectMove()">
<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.selectedIndex;
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Array in selectbox options evanburen@gmail.com Javascript 4 04-12-2007 01:39 PM
Populating a selectbox with selected value??? Si XML 1 01-30-2007 11:54 AM
Re: Javascript dropdown getting cut off by selectbox Bodidily HTML 0 08-25-2004 11:02 AM
Javascript dropdown getting cut off by selectbox danparker276@yahoo.com HTML 2 08-24-2004 10:42 PM
how to fix it:SelectBox always on top of dropdown menu item. Matthew ASP .Net 3 08-06-2003 05:23 AM



Advertisments