Shopping Cart - Updates Price live with value from drop-down option
example here: http://www.golfscene.com.au/shop/gift-voucher.html
<script>
$(function(){
/**
* When you change the option in the secondDescription <select>
* Get the text value of the option (the stuff you can see, not the value)
* Split it at the $ sign so you can get the price
* Then override the html of the cartItemPrice <div> with the new price
*/
// The select element
var select = $("[name='secondDescription']");
// The element whose HTML will be overwritten
var target = $(".cartItemPrice");
// Check to make sure both the select and target elements exist
if(select.length > 0 && target.length > 0){
// When the select changes
select.change(function(){
// Get the price by splitting the text at the $ sign
var price = $(this).children("option:selected").text().split("$");
// Update the target HTML to be "Price: $" + price[1],
// price[1] is the second index of the array, which will be everythign after the $sign
target.html("Price: $ " + price[1])
});
}
});
</script>