update the amount value by button
hi currently i have developed my own website named www.eyeview.com. i want to update the hidden amount to my add product by clicking radio buttons. i have a five radio buttons with values of 100$ 150$ 200£ 175$ and 87$ but hidden amount value is 222
var totalAmount = 222.00; //Set from the database
function updateAmount(var additionalCost)
{
document.getElementById("finalamount").innerHTML = totalAmount开发者_开发问答 + additionalCost;
}
var $amount=
(‘#repair_total_amount’).html(“Total <span class="repair-finalamount-txt">£ ”+ total_amount+”</span>”);
`$amount.text('£ 100');`
`$amount.text('£ 150');`
`$amount.text('£ 175');
`$amount.text('£ 87');
`$amount.text('£ 200');
i want to display the value on the product palce ie basket item. there is no response in my page ie nothing action after i clicked.
give me a correct code plz for updating the amount also i wanna to need the function for update
thanks in adv
Based on the fact you have tagged this post with jQuery, here is a clean jQuery solution that will work for you (just ensure you include the library of course):
<script type="text/javascript">
var startAmount = 222.0;
var finalAmount = 0;
$(document).ready(function() {
$('.c').click(function() {
$('.c:checked').each(function() {
finalAmount = startAmount + parseFloat($(this).val());
});
$('#finalAmount').html('Final Amount: $' + finalAmount);
});
});
</script>
<input name="cost" type="radio" value="100" class="c" /> 100$
<input name="cost" type="radio" value="150" class="c" /> 150$
<input name="cost" type="radio" value="200" class="c" /> 200$
<input name="cost" type="radio" value="175" class="c" /> 175$
<input name="cost" type="radio" value="87" class="c" /> 87$
<br />
<span id="finalAmount">Final Amount: $0</span>
document.getElementById('BUTTON-ID-HERE').onclick = function(){ updateAmount('VALUE HERE') };
Should be sufficent. Hope that helps.
精彩评论