-2
I have 3 fields in my form FIELD 1: which already has a value that I pulled into my database which is the product price Field 2: where I will insert a whole number indicating the amount of product I want to add Field 3: the total of the multiplication that sera Field 1(product price) X Field 2 (product quantity)
Only that doing this, the return of value in my code is giving me "Nan" and not why? I need help to understand what I did wrong. I’ve been through this for three hours and I can’t understand.DISREGARD THE FIELD WRITTEN "SALE VALUE IN R$" ON THE IMAGE
SAMPLE IMAGE
Here is my HTML condigo:
<div class="container">
<div class="row">
<div class="col-sm-3 calculate">
<label>Valor Tabelado</label>
<input type="text" class="form-control" name="valor_tabela" id="valor_tabela" value="R$<?=$put['valor_tabela']?>" readonly>
</div>
<div class="col-sm-3 calculate">
<label>Quantidade</label>
<input type="number" class="form-control" id="qty" name="quantidade" value="0">
</div>
<div class="col-sm-3 calculate">
<label>Sub Total</label>
<input type="number" class="form-control" id="result" name="sub_total" readonly>
</div>
</div>
</div>
JAVASCRIPT
<script>
$(".calculate").click(function () {
var value = '<?=$put['valor_tabela']?>';
var primaryincome = $("#qty").val();
var otherincome = $("#valor_tabela").val(value);
var totalincome = parseInt(primaryincome) + parseFloat(otherincome);
alert(totalincome);
$("#result").val(totalincome);
})
</script>
It seems that you didn’t close the tag label, this may be giving error in your html so when you go to get the input with table id, it returns Undefined. And number + Undefined returns Nan
– Eduardo Resende
I just tested and still keeps showing the "Nan"
– Gladiador
As you are doing it directly with Jquery there is no need to receive these values in so many different ways, just click on them: var value = $("#value_table"). val(); ]
– Fábio Santos