0

我想将数量乘以价格并总共“显示”。Total 需要命名为“金额”,以便将总成本转移到网关。如您所见,我正在尝试创建一个能够使用数量的解决方法。

这里的所有信息都是为​​了测试目的,所以不是个人的。

<script type="text/javascript">
function totalprice() {
    var qty = document.getElementById("quantity").value;
    var price = 219999;
    var total = (qty * price);
    document.getElementById("tot").value = total;
}
</script>

<form action="https://gateway.charityclear.com/hosted/" method="post"> 
<input type="hidden" name="merchantID" value="0000992">
<input type="hidden" name="countryCode" value="826"> 
<input type="hidden" name="currencyCode" value="826">  
<table>
<tr>
<td>Full Name </td><td><input type="text" name="customerName" value=></td></tr>
<tr>
<td>Full Shipping Address <br>(including Country)<br>(must be same as billing     address)</td><td><textarea rows="4" name="customerAddress" value=></textarea></td></tr>
<tr>
<td>Post Code </td><td><input type="text" name="customerPostCode" value=></td>          </tr>
<tr>
<td>Email Address </td><td><input type="text" name="customerEmail" value=></td> </tr>
<tr>
<td>Phone Number <br>(required for delivery)</td><td><input type="text" name="customerPhone" value=></td></tr>

<input type="hidden" name="redirectURL" value="http://www.UKRobstep.com/order- successful.html">
<tr><td></td>
</tr>
<tr><td><input type="hidden" name="orderRef" value="Colour">Colour</td>
<td>
<select name="orderRef">
<option value="Select a Colour">Select a Colour
<option value=" Robin M1 in Black">Black
<option value=" Robin M1 in White "> White
<option value=" Robin M1 in Red"> Red
<option value=" Robin M1 in Yellow ">Yellow
<option value=" Robin M1 in Silver/Grey "> Silver/Grey
</select></td>
</tr>
<tr><td>

Quantity</td><td><input type="text" name="quantity" id="quantity" class="field"  value="1" /></td></tr>
<tr><td>Price Per Unit</td><td><input type="text" name="price" id="price" class="field" value="£2199.99" readonly="readonly"/>
<input type="hidden" name="amount" id="tot" class="field" value=""/>
</td></tr>

</table>
<INPUT TYPE="image" SRC="http://www.weebly.com/uploads/9/8/2/8/9828047/5792561_orig.png" BORDER="0" ALT="Pay Now" > 
</form>

我希望有人可以提供帮助,在此先感谢。

4

2 回答 2

0

利用parseInt();

例子

function totalprice()
{
    var qty = document.getElementById("quantity").value;
    var price = 219999;
    var total = (parseInt(qty) * price);
    -------------^^^^^^^^^--------------
    document.getElementById("tot").value = total;
}
于 2013-04-09T04:10:10.343 回答
0

你只是想在用户输入数量后获得价值吗?我不确定你所说的“绕过”是什么意思。这是按下回车键后返回值的一种方式。

<script>
 function totalprice() {
    var KeyID = event.keyCode;
    if(KeyID == 13){
      var qty = document.getElementById("quantity").value;
      var price = 219999;
      var total = (qty * price);
      document.getElementById("tot").value = total;
             alert(total);
  }
  else{
  }
}

</script>


 <form action="https://gateway.charityclear.com/hosted/" method="post"> 
 <input type="hidden" name="merchantID" value="0000992">

 <input type="hidden" name="countryCode" value="826"> 
 <input type="hidden" name="currencyCode" value="826">  
 <table>
 <tr>
 <td>Full Name </td><td><input type="text" name="customerName" value=></td></tr>
 <tr>
 <td>Full Shipping Address <br>(including Country)<br>(must be same as billing      
 address)</td><td><textarea rows="4" name="customerAddress" value=></textarea></td>
</tr>
 <tr>
 <td>Post Code </td><td><input type="text" name="customerPostCode" value=></td>          
</tr>
 <tr>
 <td>Email Address </td><td><input type="text" name="customerEmail" value=></td> </tr>
 <tr>
 <td>Phone Number <br>(required for delivery)</td><td><input type="text" 
name="customerPhone" value=></td></tr>

 <input type="hidden" name="redirectURL" value="http://www.UKRobstep.com/order- 
successful.html">
 <tr><td></td>
 </tr>
 <tr><td><input type="hidden" name="orderRef" value="Colour">Colour</td>
 <td>
 <select name="orderRef">
 <option value="Select a Colour">Select a Colour
 <option value=" Robin M1 in Black">Black
 <option value=" Robin M1 in White "> White
 <option value=" Robin M1 in Red"> Red
 <option value=" Robin M1 in Yellow ">Yellow
 <option value=" Robin M1 in Silver/Grey "> Silver/Grey
 </select></td>
 </tr>
 <tr><td>

 Quantity</td><td><input type="text" name="quantity" id="quantity" class="field"    
value="1" onkeydown="return totalprice(this, event);"  /></td></tr>
 <tr><td>Price Per Unit</td><td><input type="text" name="price" id="price"  
class="field" value="£2199.99" readonly="readonly"/>
 <input type="hidden" name="amount" id="tot" class="field" value=""/>
</td></tr>

 </table><INPUT TYPE="image"    
SRC="http://www.weebly.com/uploads/9/8/2/8/9828047/5792561_orig.png" BORDER="0" 
ALT="Pay    Now" > </form>
于 2013-04-09T04:31:44.630 回答