jcourtice
asked on
Using Jquery to populate hidden form field for Paypal integration.
Hi-
I work fo a non-profit that runs a couple of therapeutic day schools for children with emotional and behavioral needs.
As part of our back to school appeal I've built a drag and drop shopping cart for a 'virtual school supply drive' that enables folks to place 'school supplies' into a 'backpack.' The jquery that I have allows for the drag and drop of the different items and updates the 'total.'
I would like to add to that script so that the value generated for the 'total' is also added into the code for a paypal button so that I can use that service to process monetary donations to our school program. What I want is for thew value of .total to be entered into the hidden amount field as the value so that paypal can process it.
Here's the jquery:
I work fo a non-profit that runs a couple of therapeutic day schools for children with emotional and behavioral needs.
As part of our back to school appeal I've built a drag and drop shopping cart for a 'virtual school supply drive' that enables folks to place 'school supplies' into a 'backpack.' The jquery that I have allows for the drag and drop of the different items and updates the 'total.'
I would like to add to that script so that the value generated for the 'total' is also added into the code for a paypal button so that I can use that service to process monetary donations to our school program. What I want is for thew value of .total to be entered into the hidden amount field as the value so that paypal can process it.
Here's the jquery:
<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('$'+totalCost);
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No problem - any time. I work a lot with designers who don't want to code so familiar with how it works.
ASKER