tags:

views:

101

answers:

2

i have to objects / elements. one is [ 4 images with different ids ] and [ a div with id container ]....

i want to make images dragable and alert the id of image if it is dragged and dropped properly inside container div.......

and then send its value to mysql with php and jquery $.ajax

+1  A: 

Use jQuery UI's Dropable

$( 'selector for DIV' ).droppable ( {
    drop: function ( event, ui ) {
        // ui.draggable is a jQuery object representing your image
    }
} );
Jan Hančič
but how can i get which image is dropped
Web Worm
the "drop" events gets the object that was draged as a parameter: http://jqueryui.com/demos/droppable/#event-drop , just read the documentation, everything is there
Jan Hančič
You use $(this) to get what object is dropped. Then you'd just have to do something like alert($(this).val('src'));
S Pangborn
No. "this" is the element that the image is being dropped on. The image is, like I said, in ui.draggable
Jan Hančič
A: 
$('#container').droppable({
   accept: 'img'
  drop: function(event, ui){
    var id=$(ui.draggable).attr('id');
    $.ajax({
      url: 'myurl.php',
      data: {id: id},
      success: function(data){
        //do something with data
      }

    })
  }
});
$('img.draggable').draggable();//assuming all draggable images have a draggable class
czarchaic