这是我的JS代码,它计算总金额:
function calTotal()
{
var a=250.00, b=175.00, c=90.00, d=415.00, e=225.00, f=225.00, g=225.00, h=225.00;
var sum = 0.00;
if(booking_form.faat_item1.checked == true){
booking_form.faat_item1.value = a;
sum += a;
}
else
booking_form.faat_item1.value = 0;
if(booking_form.faat_item2.checked == true){
booking_form.faat_item2.value = b;
sum += b;
}
else
booking_form.faat_item2.value = 0;
if(booking_form.faat_item3.checked == true){
booking_form.faat_item3.value = c;
sum += c;
}
else
booking_form.faat_item3.value = 0;
if(booking_form.osfa_item1.checked == true){
booking_form.osfa_item1.value = d;
sum += d;
}
else
booking_form.osfa_item1.value = 0;
if(booking_form.osfa_item2.checked == true){
booking_form.osfa_item2.value = e;
sum += e;
}
else
booking_form.osfa_item2.value = 0;
if(booking_form.osfa_item3.checked == true){
booking_form.osfa_item3.value = f;
sum += f;
}
else
booking_form.osfa_item3.value = 0;
if(booking_form.osfa_item4.checked == true){
booking_form.osfa_item4.value = g;
sum += g;
}
else
booking_form.osfa_item4.value = 0;
if(booking_form.osfa_item5.checked == true){
booking_form.osfa_item5.value = h;
sum += h;
}
else
booking_form.osfa_item5.value = 0;
return sum;
}
function sendTotal(){
var total = calTotal();
return total;
}
此代码计算结果很好,但我想将此计算结果直接作为金额发送到我的PayPal,以下是我的按钮代码:
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="xyz@xyz.com">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="MT1">
<input type="hidden" name="amount" value="sendTotal()">
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
商家名称已更改,我尝试直接使用此sendTotal(),但PayPal提供格式错误,任何人都可以帮助我们如何将我的JS计算总数作为PayPal的数量发送给我们。
答案 0 :(得分:0)
为您的总元素添加id属性,即id ='total',并将其添加到您的javascript中 。的document.getElementById( '合计')值= sendTotal(); 这应该有用。