I have two type of call function check_negative_value()
.
in first type I set the onchange=change_quantity(this)
and then call check_negative_value()
from there like:
function change_quantity(elem) {
check_negative_value(elem);
console.log(elem);
}
and in second type I set the decrement_cart(this)
and then call check_negative_value()
from there like:
function decrement_cart(elem) {
const input = $(elem).next('input');
check_negative_value(input);
console.log(input);
}
and in check_negative_value()
I must use input.value
or input.val()
!!
function check_negative_value(input){
if(input.value <= 0){
alert('not accept value under 1');
input.value = 1;
}
}
Or :
function check_negative_value(input){
if(input.val() <= 0){
alert('not accept value under 1');
input.val(1);
}
}
because each calling function have different element and the result of console.log
is this:
in jquery call:
r.fn.init [input.input-number.text-center, prevObject: r.fn.init(1)]
in javascript call:
<input class="input-number text-center" type="number" value="-1" min="0" max="1000" onchange="change_quantity(this)">
the html code is :
<div class="input-group-button" onclick="decrement_cart(this)">
<span class="input-number-decrement">-</span>
</div>
<input class="input-number text-center" type="number" min="0" max="1000"
onchange="change_quantity(this)">
<div class="input-group-button" onclick="increment_cart(this)">
<span class="input-number-increment">+</span>
</div>```
how can I use input element in check_negative_value()
without difference between input.val()
and input.value
???
thanks