sudeep Acharya
sudeep Acharya

Reputation: 55

The specified value "NaN" cannot be parsed, or is out of range in Jquery

I have a system where there is a select option with beneficiary account and applicant account. When ever the customer toggle between the option they get separate input fields. I am trying to get the add the field inputted by the applicant bu i am getting "The specified value "NaN" cannot be parsed, or is out of range". It is calculating properly and shows properly in result fields but show error in console and I cannot use the the result value sum.

Here is my View

Charges Details

                    <div class="row">
                <div class="form-group col-sm-4">
                        <select name = "chg" id="chg_type">
                            <option>Select</option>
                            <option value="ben_ac">Beneficiary's Account</option>
                            <option value="app_ac">Applicant's Account</option>
                        </select>
                        
                </div>
                </div>

                <div class="row">
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="nostro_amount" readonly>
                        <label>Nostro Amount<code>*</code></label>
                </div>
                        

                </div>
                <!-- Beneficiary's Account -->
                <div class="row" style="display:none" id="beneficiary_account_row">

                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="dis_fee">
                    <label>Discrepany Fee (Beneficiary)<code>*</code></label>
                </div>
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="swift_chg">
                    <label>Swfit Charge(Beneficiary)<code>*</code></label>
                </div>
                
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="ben_deduction">
                        <label>Any Deduction<code>*</code></label>
                </div>
            </div>

            <!-- End -->


                    <!-- Applicant's Account -->
                <div class="row" style="display:none" id="applicant_account_row">
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="app_dis_fee">
                    <label>Discrepany Fee(Applicant)<code>*</code></label>
                </div>
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="app_swift_chg">
                    <label>Swfit Charge(Applicant)<code>*</code></label>
                </div>
                
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="app_deduction">
                        <label>Any Deduction(In foreign)<code>*</code></label>
                </div>
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="dis_in_npr">
                        <label>Discrepany Fee(In NPR)<code>*</code></label>
                </div>
                <div class="form-group col-sm-4">
                        <input type="number" class="form-control" id="swift_in_npr">
                        <label>Swift chg(In Npr)<code>*</code></label>
                </div>
            </div>

            <!-- End -->

Here is my Jquery Code

var total_discrepancy_fee = 0;
var total_swift_fee = 0;
if($("#chg_type").val()== "app_ac" ){
  var total_discrepancy_fee = Number($('#app_dis_fee').val()) * Number($('#rate').val());
  var total_swift_fee = Number($('#app_swift_chg').val()) * Number($('#rate').val());
   $("#dis_in_npr").val(total_discrepancy_fee.toFixed(2));
   $("#swift_in_npr").val(total_swift_fee.toFixed(2));
  
}
else{
   $("#dis_in_npr").val(total_discrepancy_fee);
   $("#swift_in_npr").val(total_swift_fee);
  
}

Here is me trying to sum the result

var total_cash_from_customer = $("#usdtr_cash_amount_in_npr").val()+$("#sett_fee").val()+$("#comm_fee").val()+
$("#dis_in_npr").val()+$("#swift_in_npr").val()+$("#chq_amount").val()+$("#held_chq_amount").val()+$("#total_int").val()
+$("#additonal_chg").val()+$("#account_blc").val()-$("#blc_amount").val();

$("#customer_account").val(total_cash_from_customer.toFixed(2));

Upvotes: 0

Views: 2304

Answers (1)

sudeep acharya
sudeep acharya

Reputation: 72

Try to use Number like Number($('#rate').val() in every sum you want to do.. It will solve yr problem..

Upvotes: 1

Related Questions