폼메일 금액 계산 채택완료

3695953000_1678161381.7551.jpg

 

폼메일을 활용해서 상단 이미지와 같은 자동계산?폼을 넣고 싶습니다.

Copy
<form name="price_frm">
<table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2">부스형태</td>
    <td>단가(부스)</td>
    <td colspan="2">신청규모</td>
    <td>합계(VAT별도)</td>
  </tr>
  <tr>
    <td rowspan="2">독립부스</td>
    <td>전시</td>
    <td>1,000,000원</td>
    <td><select name="qty" id="qty">
    <option value="">선택</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
</select></td>
    <td>부스</td>
    <td><div id="it_sum1"></div></td>
  </tr>
  <tr>
    <td>엑스포</td>
    <td>500,000원</td>
    <td><select name="qty2" id="qty2">
    <option value="">선택</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
</select></td>
    <td>부스</td>
    <td><div id="it_sum2"></div></td>
  </tr>
</table>
<table border=0 cellpadding="0" cellspacing="0">
<tr>
    <td>소계</td>
    <td><div id="it_sum_all"></div></td>
</tr>
<tr>
    <td>VAT</td>
    <td><div id="it_sum_vat"></div></td>
</tr>
<tr>
    <td>납입총계</td>
    <td><div id="it_sum_total"></div></td>
</tr>
</table>
</form>

 

// jquery 영역

var sum = 0;
    $("#qty").change(function() {
    price = $("#qty option:selected").val();
    console.log(price);
    sum = parseInt(price);
    if(price) {
          $("#it_sum1").text(sum * 1000000);
    }
    });
    var sum2 = 0;
    $("#qty2").change(function() {
    price2 = $("#qty2 option:selected").val();
    console.log(price2);
    sum2 = parseInt(price2);
    if(price2) {
          $("#it_sum2").text(sum2 * 500000);
    }
    });

 

이런 식으로 해서 첫번째와 두번째 금액은 추출은 했는데

부가세와 총 합계금액을 어떻게 추출해야할까요..

 

답변 1개

채택된 답변
+20 포인트

Copy
var sum = 0;

$("#qty").change(function() {

price = $("#qty option:selected").val();

console.log(price);

sum = parseInt(price);

if(price) {

    $("#it_sum1").text(sum * 1000000);

    cal_sum();

}

});

var sum2 = 0;

$("#qty2").change(function() {

price2 = $("#qty2 option:selected").val();

console.log(price2);

sum2 = parseInt(price2);

if(price2) {

    $("#it_sum2").text(sum2 * 500000);

    cal_sum();

}

});

 

function cal_sum() {

    var sum = parseInt($("#it_sum1").text()) + parseInt($("#it_sum2").text());

    $('#it_sum_all').text(sum);

    var vat = sum * 0.1;

    $('#it_sum_vat').text(vat);

    var total = sum * 1.1;

    $('#it_sum_total').text(vat);

}
로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

감사합니다!
$('#it_sum_total').text(total);
오타가 있네요..^^;;

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고