我是JavaScript的初學者。我有代碼,用戶通過輸入字段輸入值('輸入給定費用')。我想要的是,如果用戶鍵入的值超過'1000',那麼提前值應該在另一個輸入文本('預付費')中。Javascript:通過文本字段輸入計算餘額並提前
如果用戶輸入小於'1000',那麼餘額應該來自另一個文本輸入('餘額費用')。
我Fiddle進行我的工作方式
我的HTML形式是:
<form>
<div class="tbl_admission_FormCell">Given Fees</div>
<div class="tbl_admission_FormCell" style="padding:10px;"><input type="text" name="given_fees" value="" id="given_fees" onkeypress="givenfees()" onkeyup="givenfees()"/> </div>
<div class="tbl_admission_FormCell">Balance Fees</div>
<div class="tbl_admission_FormCell"><span id="balance_fees"></span> </div>
<div class="tbl_admission_FormCell">Advance Fees</div>
<div class="tbl_admission_FormCell"><span id="advance_fees"></span> </div>
<div class="tbl_admission_FormRow">
<div class="tbl_admission_FormCell">Total Fees</div>
<div class="tbl_admission_FormCell"><input type="text" id="total_fees" name="total_fees" style="border:none;" value="1000" readonly/></div>
<div class="tbl_admission_FormCell"><div class="amt_total" onchange="amt_total()" ></div></div>
</div>
</form>
<script>
function givenfees(){
var given_fees = document.getElementById("given_fees");
var s = given_fees.value;
bal_value = +s - +result;
var balance_fees = document.getElementById("balance_fees");
if(+bal_value<0)
{
advance_fees.innerText = +bal_value;
}
else
{balance_fees.innerText = +bal_value;}
}
</script>
'result'沒有被定義! – Rayon
@rafter,我無法處理結果,我正在尋求幫助..但我已經提到了我所需的輸出.. – Keynes