I am trying to perform a multiplication between quantity and price, to get their total, however I get the following error when doing it: I do TypeError: $(...).nextElementSibling is not a function
n't know how I could modify it in such a way that it is acceptable, I share my code:
shape
<form>
<input type="text" id="quantity">
<input type="text" id="price">
<input type="text" class="result">
</form>
script
<script>
$('#quantity, #price').keyup(function(){
var cant = parseFloat(this.nextElementSibling('#quantity').val()) || 0;
var price = parseFloat(this.nextElementSibling('#price').val()) || 0;
var result = cant * price
this.nextElementSibling('.result').val(result);
})
</script>
You could search for the elements using
$('selector')
jquery, like so:nextElementSibling
It would work if you do something likedocument.getElementById("quantity").nextElementSibling
but it would select the sibling ofquantity
, which isprice
and I don't think it's very practical to use it like that, even in the case of the code I pasted the sibling would be<br>
.If you want to multiply dynamically added items, you can use classes instead of ids: