jsによる自動計算式

jsを用いた自動計算式を作りました。
jsは不慣れなので無駄の多いスクリプトです。

html

 <form name="form1">
    <table>
      <tr>
      <th><label for="r_a_fee">基本料金</label></th>
          <td>&nbsp;</td>
		  <td><input type="text" id="r_a_fee" name="one_fee" onChange="sum2()" value="">円</td>
      </tr>
      <tr>
        <th><label for="r_b_store">課金アイテムA</label></th>
        <td><input type="text" id="r_b_store" name="one_store" onChange="sum1(),sum2()" value="">個</td>
        <td><input type="text" id="r_b_fee" name="two_fee" onChange="sum2()"  value="" readonly>円</td>
      </tr>
      <tr>
        <th><label for="r_c_store">課金アイテムB</label></th>
        <td><input type="text" id="r_c_store" name="two_store" onChange="sum1(),sum2()" value="">個</td></td>
        <td><input type="text" id="r_c_fee" name="three_fee"  onChange="sum2()" value="" readonly>円</td>
      </tr>
      <tr>
        <th><label for="r_d_store">課金アイテムC</label></th>
        <td><input type="text" id="r_d_store" name="three_store" onChange="sum1(),sum2()"  value="">個</td>
        <td><input type="text" id="r_d_fee" name="four_fee"  onChange="sum2()" value="" readonly>円</td>
      </tr>    
      <tr>
        <th>合計</th>
        <td><input type="text" id="r_all_fee"  name="total_store"  value="" readonly /> 個</td>
        <td>合計<input type="text" id="r_all_fee" name="total_fee" value="" readonly>円</td>
     </tr>
    </table>
 </form>

js

    function sum1(){
    var one_store = eval(document.form1.one_store.value*1);
    document.form1.total_store.value = one_store;
     
    var two_store = eval(document.form1.two_store.value*1);
    document.form1.total_store.value = two_store;
      
    var three_store = eval(document.form1.three_store.value*1);
    document.form1.total_store.value = three_store;
    
	//合計  
    var total_store = one_store + two_store + three_store;
    document.form1.total_store.value = total_store;
  }
  
    function sum2(){
    var one_fee = eval(document.form1.one_fee.value*1);
    document.form1.total_fee.value = one_fee;
	
	//掛け算開始	  	
    var one_store = eval(document.form1.one_store.value*1);
    document.form1.two_fee.value = one_store;
     
    var sub_total1 = one_store*30000;
    document.form1.two_fee.value = sub_total1;
	
  
    var two_store = eval(document.form1.two_store.value*1);
    document.form1.three_fee.value = two_store;
     
      
    var sub_total2 = two_store*10000;
    document.form1.three_fee.value = sub_total2;
  
    var three_store = eval(document.form1.three_store.value*1);
    document.form1.four_fee.value = three_store;
     
      
    var sub_total3 = three_store*5000;
    document.form1.four_fee.value = sub_total3;
	
	//合計
	var total_fee = one_fee + sub_total1 + sub_total2 + sub_total3;
    document.form1.total_fee.value = total_fee;
	  }
  • コーダーのための計算機