Hi i have a drag and drop shopping list you drag an image with description and price into shopping basket and it adds the items to your shopping list.
but what i want to do is to be able to change the price then drag it to the shopping basket. i have tried to add a textfield where <p>Price:£0.33</input></p> is but it does not work any idea’s
here is the code i have.
html
<p class="datagrid-row-selected">Fresh Produce
</p>
<ul class="products">
<li>
<a class="item">
<img src="images/iconproducts/apple.png" width="50" height="50"/>
<div>
<p>Apples</p>
<p>Price:£0.33</input></p>
</div>
</a>
</li>
<li>
and here is the j query script
<script>
var data = {"total":0,"rows":[]};
var totalCost = 0;
$(function(){
$('#cartcontent').datagrid({
singleSelect:true
});
$('.item').draggable({
revert:true,
proxy:'clone',
onStartDrag:function(){
$(this).draggable('options').cursor = 'not-allowed';
$(this).draggable('proxy').css('z-index',10);
},
onStopDrag:function(){
$(this).draggable('options').cursor='move';
}
});
$('.cart').droppable({
onDragEnter:function(e,source){
$(source).draggable('options').cursor='auto';
},
onDragLeave:function(e,source){
$(source).draggable('options').cursor='not-allowed';
},
onDrop:function(e,source){
var name = $(source).find('p:eq(0)').html();
var price = $(source).find('p:eq(1)').html();
addProduct(name, parseFloat(price.split('£')[1]));
}
});
});
function addProduct(name,price){
function add(){
for(var i=0; i<data.total; i++){
var row = data.rows[i];
if (row.name == name){
row.quantity += 1;
return;
}
}
data.total += 1;
data.rows.push({
name:name,
quantity:1,
price:price
});
}
add();
totalCost += price;
$('#cartcontent').datagrid('loadData', data);
$('div.cart .total').html('Total: £'+totalCost);
}
</script>