views:

322

answers:

1

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.

+1  A: 

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
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
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
Any chance you can see why this code is working fine in firefox but not IE?
Chris Sobolewski
Do you have a link to this online? It's hard to tell without the full code and implementation.
Sam Wessel
Chris Sobolewski
Sam Wessel
Huh... the page I was inspred by: http://ashishware.com/MochikitDnDDemo.shtmlSeems to work OK in IE. I will give commenting out those lines a try, though.
Chris Sobolewski
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
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