2017-07-13 11 views
0

問題:計算フィールド

  • あなたは で「エア・レート」の値を「総重量」乗算に値を入力して除き、「全空気USD」 に結果を返します。 4、5、6、7、8、9 が "> 8 IF" 条件を満たし、自動的に "20"

//operation 
 
$(document).on('change keyup blur', '.changesNo', function() { 
 
    calculateTotal(); 
 
}); 
 

 
function calculateTotal() { 
 
    //AIR PRICE 
 
    totalwvariable = document.querySelector('#totalweight').value; 
 
    airtotalvar = document.querySelector('#airtotal').value; 
 
    air = $('#airrate').val(); 
 
    variable1 = 0; 
 
    if (totalwvariable > airtotalvar) { 
 
    variable1 = totalwvariable; 
 
    } else { 
 
    variable1 = airtotalvar; 
 
    } 
 
    if (variable1 > 8) { 
 
    $('#totalairusd').val(parseFloat(variable1 * air).toFixed(2)); 
 
    } else { 
 
    $('#totalairusd').val(20); 
 
    } 
 
}
.column-left { 
 
    float: left; 
 
    width: 30%; 
 
} 
 

 
.column-right { 
 
    float: right; 
 
    width: 30%; 
 
} 
 

 
.column-right2 { 
 
    float: right; 
 
    width: 17%; 
 
} 
 

 
.column-center { 
 
    display: inline-block; 
 
    width: 30%; 
 
}
<div class='row'> 
 
    <div class='col-xs-12 col-sm-12 col-md-12 col-lg-12'> 
 
    <table class="table table-bordered table-hover"> 
 
     <thead> 
 
     <tr> 
 
      <th width="10%"> 
 
      <center>Vlb (airtotal):</center> 
 
      </th> 
 
      <th width="10%"> 
 
      <center>Weight Total (totalweight):</center> 
 
      </th> 
 
     </tr> 
 
     </thead> 
 
     <tbody> 
 
     <tr> 
 
      <td> 
 
      <input type="number" class="form-control changesNo" value="35" name="airtotal" id="airtotal" ondrop="return false;" onpaste="return false;"> 
 
      </td> 
 
      <td> 
 
      <input type="number" class="form-control changesNo" name="totalweight" id="totalweight" ondrop="return false;" onpaste="return false;"> 
 
      </td> 
 
     </tr> 
 
     </tbody> 
 
    </table> 
 
    </div> 
 
</div> 
 
<div class="column-right2"> 
 
    <div class="input-group-addon">Total Air USD:</div> 
 
    <input type="number" class="form-control" name="totalairusd" readonly id="totalairusd" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"> 
 
    <br> 
 
    <div class="input-group-addon">Air Rate USD:</div> 
 
    <input type="number" class="form-control" value="2.50" name="airrate" id="airrate" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"> 
 
</div> 
 
<link href="https://www.excelintra.com/pruebas/invoice2/css/bootstrap.min.css" rel="stylesheet" /> 
 
<link href="https://www.excelintra.com/pruebas/invoice2/css/style.css" rel="stylesheet" /> 
 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" /> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> 
 
<script src="https://www.excelintra.com/pruebas/invoice2/js/bootstrap.min.js"></script>
の合計 値に移行しない:これらの数値のいずれかを入力します

+0

引数がすでに数値の場合は、 'parseFloat()'を使う必要はありません。 – Barmar

答えて

0

.valueは数字ではなく文字列を返します。あなたは

if (totalwvariable > airtotalvar) 

を行うときに、それはない数値的、辞書的に文字列を比較だ、と"8" > "10""8" > "1"ので。

数値を最初に数値に変換します。

+0

OMGありがとうございます@Barmar! –

関連する問題