keisan-2

商品名 単価 数量 金額
商品サンプル1 500円
商品サンプル2 1,000円
商品サンプル3 3,000円
合計
消費税
税込合計
<script>
function keisan(){
var tax = 8;
var price1 = document.form1.goods1.value * 500;
document.form1.field1.value = price1;
var price2 = document.form1.goods2.value * 1000;
document.form1.field2.value = price2;
var price3 = document.form1.goods3.value * 3000;
document.form1.field3.value = price3;
var total1 = price1 + price2 + price3;
document.form1.field_total1.value = total1;
var tax2 = Math.round((total1 * tax) / 100);
document.form1.field_tax.value = tax2;
document.form1.field_total2.value = total1 + tax2;
}
</script>
<form action="#" name="form1">
<table border="1" style="background-color: #ffffff;">
<tr>
<th>商品名</th>
<th>単価</th>
<th>数量</th>
<th>金額</th>
</tr>
<tr>
<td>商品サンプル1</td>
<td align="right">500円</td>
<td><input type="text" name="goods1" onChange="keisan()" value="0" size="2"></td>
<td><input type="text" name="field1" size="8" value="0"> 円</td>
</tr>
<tr>
<td>商品サンプル2</td>
<td align="right">1,000円</td>
<td><input type="text" name="goods2" onChange="keisan()" value="0" size="2"></td>
<td><input type="text" name="field2" size="8" value="0"> 円</td>
</tr>
<tr>
<td>商品サンプル3</td>
<td align="right">3,000円</td>
<td><input type="text" name="goods3" onChange="keisan()" value="0" size="2"></td>
<td><input type="text" name="field3" size="8" value="0"> 円</td>
</tr>
<tr>
<td align="right" colspan="3">合計</td>
<td><input type="text" name="field_total1" size="8" value="0"> 円</td>
</tr>
<tr>
<td align="right" colspan="3">消費税</td>
<td><input type="text" name="field_tax" size="8" value="0"> 円</td>
</tr>
<tr>
<td align="right" colspan="3"><strong>税込合計</strong></td>
<td><input type="text" name="field_total2" size="8" value="0"> 円</td>
</tr>
</table>

</form>
table{
  border-collapse: collapse;
}
td, th{
  border: solid 1px;
  padding: 0.3em;
}
td{
  text-align: right;
}
th{
  background-color: #efefef;
}
input{
  text-align: right;
}