2012-07-04 21 views
1

我在問這個問題之前搜索過。我沒有找到答案,可能是因爲我沒有在搜索時使用正確的關鍵字。

不管怎麼說,這裏是我面對:

我想從一個網站出售門票。每張票價10美元。我使用Paypal來接收付款。這個html表格包括:

<tr> 
    <td><label for="not">Number of Tickets</label></td> 
    <td><input name="not" type="text" id="not" /></td> 
</tr> 

<?php $total = $_POST['not']*10; ?>  

<input type="hidden" name="cmd" value="_xclick"> 
<input type="hidden" name="business" value="[email protected]"> 
<input type="hidden" name="currency_code" value="USD"> 
<input type="hidden" name="amount" value="<?php echo $total; ?>"> 
<input name="item_name" type="hidden" id="item_name" value="Ticket Purchase" /> 

<tr> 
    <td>&nbsp;</td> 
    <td><input type="submit" value="Pay" name="submit" /> 
</tr> 

問題是總金額是根據購買的門票數量來計算的。所以如果有人輸入5張彩票,總金額應該是50美元,它將被用作「金額」變量內的值。但是,PayPal沒有獲得總價值。所以我想知道我應該如何去發佈一個可變數量內?

由於提前, 尼薩爾

回答

2

我想你會過得更好計算與使用Javascript/jQuery的總量和更新這種方式。

如果你使用jQuery這樣的事情

$("#not").change(function() 
{ 
    var total = $("#not").val() * 10; 
    $("#total").val(total); 
}); 

改變

<input type="hidden" name="amount" value="$total"> 

<input type="hidden" name="amount" value="" id="total"> 

然後腳本括號內雖然你仍然需要做數據驗證,即確保「不是「是一個整數。

希望有所幫助。

感謝

尼古拉斯

+0

沒錯!這工作。太感謝了。我將添加驗證以僅允許那裏的數字。 – asprin