0

error:-The specified value "NaN" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+.\d+|.\d+)([eE][-+]?\d+)?

when i place the values in input values the in quantity and in rate, then expected result of input likes should be 4*5 = 20 but it doesn't do so instead 4*5a where a is the variable where any value of integer is placed then it only gives the expected result 20

<table>
 <tr v-for="(pro,index,k) in pr`enter code here`oduct" :key="k">
<td>{{index+1}}</td>
<td><input type="number" v-model="pro.qnt" @keypress="calculatetotal(index)" style="width:110px;"></td>
<td><input type="number" v-model="pro.rate" @keypress="calculatetotal(index)" style="width:110px;"></td>
<input type="number" v-model="pro.totalamount" class="form-control"></td>
 <td><input type="number" v-model="pro.Amount" style="width:110px;" @keypress="discountamount(index)"></td>
                                    <td><input type="number" v-model="pro.discount" style="width:110px;"  @keypress="discountamount(index)" :disabled = "selected===1"></td>
                                    <td><input type="number" v-model="pro.totalamount" class="form-control"></td>
  </table>


methods:{
  calculatetotal: function(index)
            {
                var total;
                total=this.product[index].qnt * this.product[index].rate;
                this.product[index].Amount=total
            },

 discountamount: function(index)
            {

                //check whether the discoun is disabled or not
                if( this.selected===1)
                {
                  this.product[index].totalamount=this.product[index].Amount
                }
                else{
                var dsa;
                dsa=this.product[index].Amount - this.product[index].discount;
                this.product[index].totalamount = dsa
                }
            }

  }

the output should be 2*4=8 but it gives 2*4=0 and gives correct answer when 2*4a where a is integer varaible then only gives expected result 8

Leonardo Rossi
  • 2,922
  • 2
  • 20
  • 28

1 Answers1

0

If you take a look at this answer : https://stackoverflow.com/a/3396805/5543999 You will see that with the event on key press, the input is not already altered. Change your @keypress for @keyup and everything should work properly.

Elie Morin
  • 1,456
  • 3
  • 15
  • 35