Web Worm
Web Worm

Reputation: 2066

jquery drag drop values with php

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

Upvotes: 1

Views: 858

Answers (2)

czarchaic
czarchaic

Reputation: 6318

$('#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

Upvotes: 0

Jan Hančič
Jan Hančič

Reputation: 53930

Use jQuery UI's Dropable

$( 'selector for DIV' ).droppable ( {
    drop: function ( event, ui ) {
        // ui.draggable is a jQuery object representing your image
    }
} );

Upvotes: 1

Related Questions