list box to list box 
Author Message
 list box to list box

I am writing some javascript so that users can add , remove and sort a
selection of items.

 The system uses a right box of selected items populated from a record which
may be removed or sorted.
The left box of items is populated by the remaining options not currently
held in the record. An item may only be either in or out of the record (ie
left or right).

Everything works fine except for one problem with the add or remove feature:

 I can not seem to create a new option in a particular select box.

eg removing from the right and putting on the end of the left does not work:
selectboxleft.options[lengthofleft] = selectboxright.options[i]
(or a modified version to replace the value and text seperately)

But  replacing an existing option does work:
eg options[lengthofleft-1]  will put the value to remove across to the left
by replacing the last value on the left

Does anyone know if it is actually possible to create new options once a
select box is written?

Many thanks

Jon Shaw



Fri, 18 Jul 2003 10:35:11 GMT  
 list box to list box

The following works fine in IE5.5, and should also be fine in IE5.0.
Since it's pure DOM, it should also work just fine in NN6, though I
didn't test that...

<script>
function MoveOption(x){
    var y=x[x.selectedIndex], c=y.cloneNode(true);
    y.parentNode.removeChild(y);
    y=document.getElementById('Sel1');
    // Next line positions moved option 1st...
    y.insertBefore(c,y.options[0]); y.options[0].selected=true;
        // Or, substitute next line to position last instead...
        // y.appendChild(c); c.selected=true;
    if (x.length<2) x.parentNode.removeChild(x)}
</script>

<p><select id="Sel1">
<OPTION value="cR">Red</OPTION>
<OPTION value="cY">Yellow</OPTION>
<OPTION value="cB">Blue</OPTION>
</select></p>

<p><select id="Sel2" onchange="MoveOption(this.options)">
<OPTION>Select...</OPTION>
<OPTION value="fA">Apple</OPTION>
<OPTION value="fP">Peach</OPTION>
<OPTION value="fG">Grape</OPTION>
</select></p>

- Peter

Quote:

> I am writing some javascript so that users can add , remove and sort a
> selection of items.

>  The system uses a right box of selected items populated from a record which
> may be removed or sorted.
> The left box of items is populated by the remaining options not currently
> held in the record. An item may only be either in or out of the record (ie
> left or right).

> Everything works fine except for one problem with the add or remove feature:

>  I can not seem to create a new option in a particular select box.

> eg removing from the right and putting on the end of the left does not work:
> selectboxleft.options[lengthofleft] = selectboxright.options[i]
> (or a modified version to replace the value and text seperately)

> But  replacing an existing option does work:
> eg options[lengthofleft-1]  will put the value to remove across to the left
> by replacing the last value on the left

> Does anyone know if it is actually possible to create new options once a
> select box is written?

> Many thanks

> Jon Shaw



Sat, 19 Jul 2003 16:50:48 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. add, edit using drop down boxes and list boxes

2. Populate list box based on selection in another list box.

3. Server Side List Box

4. List Boxes

5. Newbie List Boxes

6. Show text from a list box

7. What to do when handling Rec Set and populating list box

8. Directory list box

9. List boxes

10. List Box question

11. On click event to make a list box visible

12. dropdown list box

 

 
Powered by phpBB® Forum Software