Moving all items from one Scriptaculous box to another

O

OwlHoot

I am using Thomas Fuchs's amazing drag-and-drop JavaScript library
available at:

http://wiki.script.aculo.us/scriptaculous/show/DragAndDrop

to allow the user to select a subset of items listed in one box by
dragging them to another and sort them in the latter, and it works
a treat.

However, I'd now like to add a couple of buttons, "<<" and ">>" between
the pair of boxes so that the user can shuffle all the items from one
box
to the other and back again in a single click.

But I'm eternally ***ed if I can get the code to work, even after
spending
three hours on it, and was wondering if an expert might spot something
obvious or even have done the same thing. Anyway, the relevant code
is as follows:

(in page header ..)

<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js" type="text/javascript"></script>

<script type="text/javascript">
// <![CDATA[

function spt_form_submit()
{
document.spt_main_form.spts.value=
Sortable.sequence("secondlist").join("' . '_' . '");

return true;
}

// ]]>
</script>';


(Following defines the two boxes, selectable ("firstlist") and selected
("secondlist")
with the two buttons between them:

* "choose_none" that is supposed to shuffle every item back to the
"selectable" list and empty the "selected" list

* "choose_all' that is supposed to do the opposite. Currently
"choose_all"
has only a JavaScript stub, until I can get the "choose_none" button
working! )


<table width="800px">

<tr><td width="40%"><h3 style="text-align:center">Selectable Items</h3>

<ul class="sortabledemo" id="firstlist" style="height:200px;
margin:2px; overflow:auto; border:1px solid black;"><li id="id_1">Item
1</li>;"><li id="id_2">Item 2</li> .. </ul></td>


<td width="20%"><center><table>
<tr><td><input type="submit" name="choose_none" value="&lt;&lt;"
onClick="' .

flist = document.getElementById(\'firstlist\');
slist = document.getElementById(\'secondlist\');

var flth = flist.length;
var slth = slist.length;

for (var i = 0; i < slth; i++)
{
flist.appendChild(slist.options.item);
}

slist.length = 0;

Sortable.destroy(\'firstlist\');
Sortable.destroy(\'secondlist\');

Sortable.create(\'firstlist\',

{dropOnEmpty:true,containment:[\'firstlist\',\'secondlist\'],constraint:false});
Sortable.create(\'secondlist\',

{dropOnEmpty:true,handle:\'handle\',containment:[\'firstlist\',\'secondlist\'],constraint:false});'
..
'return false;"></td></tr>
<tr><td>&nbsp</td></tr>
<tr><td><input type="submit" name="choose_all" value="&gt;&gt;"
onClick="return false;"></td></tr>
</table></center></td>


<td width="40%"><h3 style="text-align:center">Selected Items</h3>
<ul class="sortabledemo" id="secondlist" style="height:200px;
margin:auto; overflow:auto; border:1px solid black;"></ul></td></tr>

</table>

<script type="text/javascript">
// <![CDATA[
Sortable.create("firstlist",

{dropOnEmpty:true,containment:["firstlist","secondlist"],constraint:false});
Sortable.create("secondlist",

{dropOnEmpty:true,handle:\'handle\',containment:["firstlist","secondlist"],constraint:false});
// ]]>
</script>';


I think that should be enough to give a reasonable idea of what I'm
trying
to achieve, and if anyone has any thoughts or obvious (or what should
be obvious!) observations, I'll be very interested.

Note that I've plugged a couple of variable values with hard-coded
text,
to make the sample easier to follow. So don't worry about minor syntax
errors - I think my problems go somewhat deeper than that!



Cheers

John Ramsden
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top