views:

163

answers:

1

I'm currently using scriptaculous and prototype to drag/drop elements from one div to another, and append a new Element based on the 'src' of the element that is dropped, creating a new draggable out of it.

What I need to do is assign the id of the dropped element to the new one once it is created.

I've tried a ton of different approaches, here is the latest:

$$('.image').each(function(stack) {
new Draggable(stack, { revert: true, ghosting: true }); 
});

...

onDrop: function(stack) {
      var added = new Element('img');
      added.src = stack.readAttribute('src');
      var imageid = stack.identify();
   added.setAttribute('id', imageid);

obviously I'm a bit of a novice, and imagine I am way off by now. Appreciate any help.

+1  A: 

Most of your code seems sound however I wanted to make sure that div object being dropped on is Droppable. The Draggable class doesn't have an onDrop callback function. If you look at the documentation it has an onStart, onDrag, change, and onEnd. Try using onEnd instead.

http://wiki.github.com/madrobby/scriptaculous/draggable http://wiki.github.com/madrobby/scriptaculous/droppables

Paulo