My Code in Fiddle: http://jsfiddle.net/wguan/7yMSz/
The current code allows one to drag and drop between two div boxes. But I was wondering how to auto sort by default so that when i drag between the boxes, both will automatically sort from smallest number on top to largest number at the bottom.
HTML
<div id="boxes_holder" class="initBox">
<div draggable="true" class="boxes" style="text-align:center;">1</div>
<div draggable="true" class="boxes" style="text-align:center;">2</div>
<div draggable="true" class="boxes" style="text-align:center;">3</div>
<div draggable="true" class="boxes" style="text-align:center;">4</div>
</div>
<div id="dragBox" class = "initBox">
<div id="dragBoxTitle" class = "">Box</div>
</div>
CSS:
#boxes_holder{
width:100px;
height:100px;
border:0px;
display: inline-block;
float: left;
vertical-align:top;
background-color:#FBFBFB;
list-style-type: none;
}
#dragBox{
width:100px;
height:100px;
border:0px;
display: inline-block;
float: right;
vertical-align:top;
background-color:#FBFBFB;
list-style-type: none;
}
Javascript:
$(document).ready(function () {
$('#boxes_holder, #dragBox').sortable({
connectWith: '.initBox',
//Whenever Dropped Item
receive: function (event, ui) {
if ($(this).children().length > 4) {
if ($(this).attr('id') == 'dragBox') {
$(ui.sender).sortable('cancel');
}
}
}
});
});
My Actual HTML Code with PHP below (doesn't seem to work):
<div id = "boxes_holder" class = "initBox">
<?php
//Creates 49 BOXES elements
$x = 49;
for($i=1; $i<=$x; $i++){
echo '<li><span class = "boxes" style="text-align:center;float:left;margin:10px;" > '.$i.'</span></li>';
}
?>
</div>
<div id="dragBox" class = "initBox">
<div id="dragBoxTitle" class = "">
Pick Your Numbers:
</div>
</div>