Hey,
I have a shopping cart for music that lets users sample tracks from a playlist. Each track has a ‘buy now’ button (the bold code below). The code that generates the tracks is the first section of code I will post. The goal is to dynamically replace the ‘product_image’ button in bold, for the track clicked on, with a checkmark image that we have (checkmark.png).
Below is the code that I use to generate the playlist tracks along with their individual ‘buy now’ button.
$("#jplayer_playlist ul").empty();
for (i=0; i < myPlayList.length; i++) {
var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a> <a href='#' id='jplayer_playlist_item_"+i+"' class='playlistItem'>[B]<span id='new_image'><img src='http://www.mysite.com/images/product_buy_2_transparent.gif' BORDER='0' align='right'></span>[/B]</a></li> ";
To capture the click of the dynamically generated playlist item, I use this:
[B]$("#jplayer_playlist ul a").live("click", function()[/B] {
When I receive word from my json response page that the item was added, I use the following code to dynamically send a message to users:
jQuery[B]("#show_update").html[/B]("<font size='2'><b>The item has been added to your cart. <a href='cart.php'>View Cart</a> <a href='checkout.php'>Checkout</a></b></font>");
I bolded the .html part to show you how I can update divs or spans to reflect a message to alert them if the product was added to the cart or if the action failed for whatever reason.
So the question is, how do I use something similiar to .html and update the span, in the first block of code that is bolded, up at the top, to change the ‘buy now’ product image with a ‘checkmark’ image?
The idea is that we can not only alert them that the product was added - but make it impossible for them to try again while making it a nicer visual experience for the user. I can update static div/span elements once the JSON response comes back after a track is clicked on. Just not the unique track that was clicked on.
Thanks.