views:

267

answers:

2

Hi All,

With the help of the stackoverflow community, I've got the dragging to work perfectly using JQuery. Now, I've assigned a .drop class (and made it .droppable), but whenever I drop a .draggable onto the .droppable... nothing happens! Is there an error in javascript?

<script type="text/javascript">  
  $(document).ready(function() {  
doReady();  

var prm = Sys.WebForms.PageRequestManager.getInstance();  
prm.add_endRequest(function(s, e) {  
    doReady();  
});  
});  

function doReady() {
$('.drag').draggable({ revert: true,helper: 'clone' });}
$('.drop').droppable({ 
tolerance: touch,
drop: function() { alert('dropped'); }
});
</script>

The top part of the script allows to the Drag & Drop goodness to continue working after a partial postback.

A: 

Did you miss the } on the end of your doReady() function?

fd
I don't think I did? I counted the # of opening {'s and closing }'s - and they seem to match up. As far as the rest of the opening and closing statements, I think I've thoroughly confused myself from modifying a bunch of existing code snippets. The concept of opening and closing tags is a bit new to me, as I've never had to use the ; in VB.net :D
Bill Sambrone
Ah, yes I see you slipped a '}' at the end of the $('.drag')... line. Meaning the $('.drop')... line is not in doReady().
fd
+1  A: 

Here should be a string

tolerance: "touch",

I format your code

  $(document).ready(function() {  

     doReady();  

     var prm = Sys.WebForms.PageRequestManager.getInstance();  
     prm.add_endRequest(function(s, e) {  
         doReady();  
     });  

  }); // End of document ready

  function doReady() {

    $('.drag').draggable({ revert: true,helper: 'clone' });

  } // End of do ready

  $('.drop').droppable({ 
     tolerance: "touch", // Here should be a string
     drop: function() { alert('dropped'); }
  });

Can you see $('.drop') is not in doReady function.

Fixed.

function doReady() {

   $('.drag').draggable({ revert: true,helper: 'clone' });
   $('.drop').droppable({ 
      tolerance: "touch", // Here should be a string
      drop: function() { alert('dropped'); }
   });

 } // End of do ready
Gordian Yuan
I updated it, and it seems to be status quo? Whenever I drop something onto the label marked as .drop, it will never trigger the alert function to let me know it registered a drop.
Bill Sambrone
I have updated my answer
Gordian Yuan
That was it! Perfect! Next time I will pay closer attention to where the opening and closing tags are versus the number of them. I really appreciate your help!!!
Bill Sambrone