샐렉트 값에 따라 결과값이 틀리게 나오게

샐렉트 값에 따라 결과값이 틀리게 나오게

QA

샐렉트 값에 따라 결과값이 틀리게 나오게

답변 1

본문

가장 먼저 샐렉트메뉴에서 304 또는 316L을 선택하게 되는데요

304를 선택할시에는 그냥 값이 나오면 되는데

316L을 선택했을때는 두배(x2)값으로 나오게 하려면 어떻게 해야할까요?ㅜㅜ

고수님들의 도움 부탁드립니다.

감사합니다.

 

 

<?php
include './_common.php';
include_once G5_THEME_PATH.'/head.php';
?>
<section class="content_wrap">
  <div class="txtCon">
    <div class="non-payment_area">
       <div class="content-box"> 
          <table class="tbl-stat" id="tbl-rank">
            <caption>
            </caption>
            <colgroup>
            
            <col style="width: 33.33333%;">
                
            </colgroup>
            <thead>
             
               <tr>
                <th scope="col">
<div style="margin:10px 0">
                        <select class="form-select unit" required><!--여기서 선택을 합니다.-->
                            <option value="">강종 선택</option>
                            <option value="304">304</option>
                            <option value="316l">316L</option>
                        </select>

                    </div>
                    
<div style="margin:10px 0">
  <label for="price" style="display:block;margin-bottom:5px">외경</label>
  <input type="text" id="price" style="outline: 1px solid #000;" placeholder="입력" onkeyup="calculateResult()">
</div>
<div style="margin:10px 0">
  <label for="price1" style="display:block;margin-bottom:5px">두께</label>
  <input type="text" id="price1" style="outline: 1px solid #000;" placeholder="입력" onkeyup="calculateResult()">
</div>
<div style="margin:10px 0">
  <label for="result" style="display:block;margin-bottom:5px">외경-두께</label>
  <input type="text" id="result" style="outline: 1px solid #000;" placeholder="자동계산" readonly>
</div>
<div style="margin:10px 0">
  <label for="result1" style="display:block;margin-bottom:5px">(외경-두께)-두께</label>
  <input type="text" id="result1" style="outline: 1px solid #000;" placeholder="자동계산" readonly>
</div>
<div style="margin:10px 0">
  <label for="result2" style="display:block;margin-bottom:5px">(외경-두께)-두께*0.02491</label>
  <input type="text" id="result2" style="outline: 1px solid #000;" placeholder="자동계산" readonly>
</div>
<div style="margin:10px 0">
  <label for="price2" style="display:block;margin-bottom:5px">구조율</label>
  <input type="text" id="price2" style="outline: 1px solid #000;" placeholder="입력" onkeyup="calculateResult()">
</div>
<div style="margin:10px 0">
  <label for="result3" style="display:block;margin-bottom:5px">산출값</label>
  <input type="text" id="result3" style="outline: 1px solid #000;" placeholder="자동계산" readonly>
</div>


<script>
  function calculateResult() {
    let price = document.getElementById('price').value;
    let price1 = document.getElementById('price1').value; 
    let result = price - price1; 
    let result1 = (price - price1) * price1;
    let result2 = (price - price1) * price1 * 0.02491; 
    let price2 = document.getElementById('price2').value; 
    let result3 = (price - price1) * price1 * 0.02491 * price2;   
    document.getElementById('result').value = result;
    document.getElementById('result1').value = result1;
    document.getElementById('result2').value = result2; 
    document.getElementById('result3').value = result3;     <!--여기가 최종 결과값입니다.-->
  }
</script></th>
              </tr>    
            </thead>
         
          </table>
        </div>
    </div>
  </div>
</section>
<!--content_wrap-->

<?php
include_once(G5_THEME_PATH . '/tail.php');
?>
 

이 질문에 댓글 쓰기 :

답변 1

let result3 = (price - price1) * price1 * 0.02491 * price2;   

하단에 다음코드를 추가하면 될 것 같습니다. 

 

if (document.querySelector('.form-select').value == '316l') {
    result3 = result3 * 2;
}

답변을 작성하시기 전에 로그인 해주세요.
전체 3
© SIRSOFT
현재 페이지 제일 처음으로