Reputation: 45
Based on my search on internet I found that I have to set an onclick event to my code so I have changed the jQuery function to be called on click as bellow:
$.fn.addcart = function(item) {
alert ("im running ");
// Create a new AJAXPaypalCart Object
var cart = $('#cart').DCAJAXPaypalCart({
width:600,
autoOpenWhenAdd:true,
openNewCheckOutWindow:true,
//themeColor:'#333',
//themeDarkColor:'#FFF',
header:'Globuy Shopping Cart',
footer:'We accpet paypal, visa and master card, Sberbank, Bank of China, Persian Bank',
paypalOptions:{
business:'[email protected]',
page_style:'digicrafts'
}
});
// Add the button
cart.addBuyButton("#macbook",{
name:"test",
// Item name appear on the cart
thumbnail:'media/macbook.jpg', // Thumbnail path of the item (Optional)
price : $('#pricetag').text(),
// Cost of the item
shipping:20 // Shipping cost for the item (Optional)
});
// For code highlight
prettyPrint();
};
here is PHP dynamically generated shopping cart
while($row = mysqli_fetch_array($result))
{
$pic = 'image/'.$row['2'];
echo "<li><div class='prod_boxpage'>
<div class='center_prod_box'>
<div class='product_title'><a href='http://www.free-css.com/'>Makita 156 MX-VL</a> </div>
<div class='product_img'><a href='http://www.free-css.com/'><img src='".$pic."' alt='".htmlspecialchars($row['1'])."' width='50' height='50' class='pngfix' /></a></div>
<div class='prod_price'><span class='reduce'>350$</span> <span class='price'><a id='pricetag'>270</a>$</span></div>
</div>
<div class='prod_details_tab'>
<div class='caption'>
<div class='text'>
<div class='sub'>
</div>
</div>
<div class='button' id='macbook' onClick='$(this).addcart('item');'><a class='prod_buy' >Add to Cart</a> <a class='prod_details'>Details</a> </div>
</div>
</div>
</div>
</li>
My current problem is I can't get the jQuery function running on click. Is there anything wrong with my onclick passing argument?? It's supposed to add the price from pricetag to the shopping cart. Please help.
Upvotes: 1
Views: 200
Reputation: 21034
Try using jQuery:
...
price : $('#pricetag').text(), // document.getElementById("pricetag").textContent,
...
Upvotes: 4