Der var en lille fejl, men det er rettet nu.
Her er hele koden, og det virker. Er testet :)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/ (...)
<html xmlns="
http://www.w3.org/ (...)
<head>
<title>JQuery Drag and Drop</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.19.custom.min.js"></script>
<style type="text/css" media="screen">
#Wrapper
{
margin: 50px auto 0;
width: 971px;
font-size: 0;
text-align: center;
}
.DragSource, .DestinationWrapper
{
width: 300px;
height: 400px;
border: 1px solid #000;
display: inline-block;
vertical-align: top;
text-align: left;
margin-right: 40px;
}
.DestinationWrapper
{
border: none;
}
.DragSource
{
margin-right: 40px;
}
.DragDestination
{
width: 300px;
height: 190px;
border: 1px solid #000;
display: block;
vertical-align: top;
text-align: left;
}
.DragDestination:first-child
{
margin-bottom: 20px;
}
.DragBox
{
width: 120px;
height: 35px;
border: 1px solid #000;
display: inline-block;
margin: 10px;
font-weight: bold;
background-color: #FFF;
font-size: 15px;
font-family: Verdana;
text-align: center;
padding-top: 15px;
vertical-align: top;
cursor: move;
}
.Green
{
background-color: #0F0;
}
.Blue
{
background-color: #00F;
}
.Orange
{
background-color: #FA0;
}
.Red
{
background-color: #F00;
}
.Pink
{
background-color: #FAA;
}
.Cyan
{
background-color: #0FF;
}
.Gray
{
background-color: #999;
}
.White
{
background-color: #FFF;
}
</style>
</head>
<body>
<div id="Wrapper">
<form id="MyForm" action="postback.php" method="post">
<div class="DragSource">
<div class="DragBox Green">
<input type="hidden" name="GreenBox" value="0" />
</div>
<div class="DragBox Blue">
<input type="hidden" name="BlueBox" value="0" />
</div>
<div class="DragBox Orange">
<input type="hidden" name="OrangeBox" value="0" />
</div>
<div class="DragBox Red">
<input type="hidden" name="RedBox" value="0" />
</div>
<div class="DragBox Pink">
<input type="hidden" name="PinkBox" value="0" />
</div>
<div class="DragBox Cyan">
<input type="hidden" name="CyanBox" value="0" />
</div>
<div class="DragBox Gray">
<input type="hidden" name="GrayBox" value="0" />
</div>
<div class="DragBox White">
<input type="hidden" name="WhiteBox" value="0" />
</div>
</div>
<div class="DestinationWrapper">
<div class="DragDestination">
</div>
<div class="DragDestination">
</div>
</div>
</form>
</div>
<script type="text/javascript">
$(".DragBox").draggable({
start: function ()
{
$(this).parent().droppable("enable");
},
revert: true
});
$(".DragDestination").droppable(
{
drop: function (event, ui)
{
var elem = $(ui.draggable[0]);
elem.css("left", "");
elem.css("top", "");
elem.appendTo(this);
elem.children("input").val("1");
$(this).droppable("disable");
}
});
$(".DragSource").droppable(
{
drop: function (event, ui)
{
var elem = $(ui.draggable[0]);
elem.css("left", "");
elem.css("top", "");
elem.appendTo(this);
elem.children("input").val("0");
}
});
</script>
</body>
</html>