0

I found some interesting code when I was looking at things that people had added on to Scriptaculous, and I'm trying to modify it for my purposes. I got nearly all of it working, except when I paste in the drop handler code, my page stops loading.

Here's the relevant snipits:

For draggables:

for (i=0; i<=50; i++){
     Squad = 'Squad' + i
     if($(Squad)){
          new Draggable(Squad,{revert:true});

For Droppables:

Droppables.add('ToEast', {
     accept: ["Nurse","Squad","Doctor"], 
     onDrop:function(e){DropHandler(e,'ToEast')}
});

The drophandler:

 function DropHandler(element,el){
     var newnode  = document.createElement('img'); 
     var classname = element.className;
     newnode.src="images/"+IdCatcher+".jpg";
     newnode.id = IdCatcher;  
     $(el).appendChild(newnode);
     newnode.setAttribute("class", 'classname');
     newnode.setAttribute("className", 'classname);
     new Draggable(newnode.id,{revert:true});
     element.parentNode.removeChild(element);
 }

I replaced the code with "alert()" and it started working fine, so something in that last block isn't working well. I had to modify a lot of their code to make it work with the current version of scriptaculous, but i'm not all that familiar, so it could have something to do with old code? Or there could just be something wrong with it that I'm not good enough to see.

Chris Sobolewski
  • 12,819
  • 12
  • 63
  • 96

1 Answers1

1

You are missing a closing quote on the end of this line:

newnode.setAttribute("className", 'classname);

If there's still a problem, I suggest you try debugging the script using Firebug to see which line causes an error.

Sam Wessel
  • 8,830
  • 8
  • 40
  • 44
  • Well I feel dumb. I couldn't use firebug because the code was completely failing to run... which really should have made me think it was something like a missing quote or bracket. Sorry, very new coder here. – Chris Sobolewski Aug 10 '09 at 15:35
  • Don't feel dumb... I only spotted it thanks to StackOverflow's syntax highlighting! We all work in wtf/min around here :) (feel free to drop me an upvote though) – Sam Wessel Aug 10 '09 at 15:53
  • Any chance you can see why this code is working fine in firefox but not IE? – Chris Sobolewski Aug 10 '09 at 17:11
  • Do you have a link to this online? It's hard to tell without the full code and implementation. – Sam Wessel Aug 10 '09 at 18:53
  • I fixed it to the point that it doesn't make doezens of copies of itself like it used to, but drag&drop is still very broken on IE6. Dorry for the delay, this is an internal project for work so I had to sanitize it and upload it to my personal webserver. http://lakepcrepair.net/draganddropdemo/locator.html – Chris Sobolewski Aug 10 '09 at 22:05
  • 1
    It throws "object required" errors in IE7/8 as well, at line 361 in effects.js - this is a check for IE haslayout issues. Looks like a scriptaculous bug with IE. Try commenting out lines 361 & 362, and making sure the elements have layout http://haslayout.net/haslayout so you don't need that check. – Sam Wessel Aug 11 '09 at 09:31
  • Huh... the page I was inspred by: http://ashishware.com/MochikitDnDDemo.shtml Seems to work OK in IE. I will give commenting out those lines a try, though. – Chris Sobolewski Aug 11 '09 at 12:21
  • Sir, if you know any other ways I can give you rep, I am more than happy to do it. This worked, my page is working great now. – Chris Sobolewski Aug 11 '09 at 12:32
  • Chris, you are most welcome. I have felt the pain of haslayout on many occasions and am only too happy I could be of assistance. – Sam Wessel Aug 11 '09 at 13:05