2016-04-19 12 views
0

なんらかの理由で私の合計が* 10です。私はどこかで愚かな間違いを犯しました。フォームの計算方法を私はビルドしていますが、最後の要素に固執しています。JS GSTの計算フォームの合計がそれ以上のものを掛ける場合

gst入力には小数点以下桁がありません。この時点ではあまり苦労していませんが、後で追加することはできますが、+要素と出力の両方を追加する必要があります。 `多分;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 

<body> 
<script type="text/javascript"> 
function updatePrice() { 
     // Get the ex-GST price from its form element 
var exPrice = document.getElementById("ex-gst").value; 
var TPrice = document.getElementById("gst").value; 

// Get the GST price 
gstPrice = exPrice * 0.1; 
TPrice = gstPrice + exPrice; 

// Set the GST price in its form element 
document.getElementById("gst").value = gstPrice; 
document.getElementById("inc-gst").value = TPrice; 

} 
</script> 

<table border=0 cellspacing=2 cellpadding=2> 
     <tr> 
     <th width="5"> </th> 
     <th width="264"> </th> 
     <th><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Attendees</font></th> 
     </tr> 
     <tr> 
     <td align=center> </td> 
     <td align=right>Calculate</td> 
     <td align=right> <input id="ex-gst" name="ex-gst" value="0.00" size=7 maxlength=10 onChange="updatePrice()"></td> 
     </tr> 
     <tr> 
     <td align=center> </td> 
     <td align=right> 12.5% G.S.T </td> 
     <td align=right> <input type=text id="gst" name="gst" size=7 maxlength=10 value="0.00" onChange="updatePrice()"></td> 
     </tr> 
     <tr> 
     <td align=center> </td> 
     <td align=right>Total Payable</td> 
     <td align=right> $ 
      <input name="inc-gst" id="inc-gst" type="text" value="0.00" size=7 maxlength=10 onChange="updatePrice(this.form)"> 
     </td> 
     </tr> 
    </table> 


</body> 
</html> 
+0

' gstPrice = exPrice * 0.1をしなければなりませんでしたか? – Steve

答えて

0

はそれが働いて得た、ただ若干の編集

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 

<body> 
<script type="text/javascript"> 
function updatePrice() { 
     // Get the ex-GST price from its form element 
var exPrice = document.getElementById("ex-gst").value; 
var gstPrice = document.getElementById("gst").value; 

// Get the GST price 
gstPrice = exPrice * 0.1; 
var TPrice = parseInt(gstPrice) + parseInt(exPrice); 

// Set the GST price in its form element 
document.getElementById("gst").value = gstPrice; 
document.getElementById("inc-gst").value = TPrice; 

} 
</script> 

<table border=0 cellspacing=2 cellpadding=2> 
     <tr> 
     <th width="5"> </th> 
     <th width="264"> </th> 
     <th><font size="2" face="Geneva, Arial, Helvetica, sans-serif">Attendees</font></th> 
     </tr> 
     <tr> 
     <td align=center> </td> 
     <td align=right>Calculate</td> 
     <td align=right> <input id="ex-gst" name="ex-gst" value="0.00" size=7 maxlength=10 onChange="updatePrice()"></td> 
     </tr> 
     <tr> 
     <td align=center> </td> 
     <td align=right> 12.5% G.S.T </td> 
     <td align=right> <input type=text id="gst" name="gst" size=7 maxlength=10 value="0.00" onChange="updatePrice()"></td> 
     </tr> 
     <tr> 
     <td align=center> </td> 
     <td align=right>Total Payable</td> 
     <td align=right> $ 
      <input name="inc-gst" id="inc-gst" type="text" value="0.00" size=7 maxlength=10 onChange="updatePrice(this.form)"> 
     </td> 
     </tr> 
    </table> 


</body> 
</html> 
+0

これは 'parseFloat()'でなければなりません。そうしないと、小数点は無視され、整数に変換されます。 'gstPrice = parseFloat(exPrice)* 0.1; TPrice = parseFloat(gstPrice)+ parseFloat(exPrice); ' –

関連する問題