需要计算2个输入字段,并显示在第三

need to calculate 2 input fields and display in 3rd

本文关键字:显示 字段 计算 2个 输入      更新时间:2023-09-26

我想用数量乘以价格和'显示'的总和。Total需要命名为"amount",以便将总成本转移到网关。正如你所看到的,我正在尝试创造一个能够使用数量的方法。

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

<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>

我希望有人能帮忙,提前谢谢。

use parseInt();

function totalprice()
{
    var qty = document.getElementById("quantity").value;
    var price = 219999;
    var total = (parseInt(qty) * price);
    -------------^^^^^^^^^--------------
    document.getElementById("tot").value = total;
}

你只是想在用户输入数量后获得价值吗?我不太明白你说的"四处走走"是什么意思。这是一种在按下回车键后返回值的方法。

<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>