0
Colleagues.
I have a select that is bringing the stocks from a database. I’m capturing it this way:
<select name='estoque' id='estoqueProdutos'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
</select>
Jquery
function alterar(){
var estoques = $('#estoqueProdutos').val();
var estoque = document.getElementById("estoque").value = estoques;
}
Each stock will limit the amount of the button below:
Which is represented as follows:
$('.value-plus1').on('click', function(){
var estoqueProduto = document.getElementById("estoque").value;
var divUpd = $(this).parent().find('.value1'), newVal = parseInt(divUpd.text(), 10)+1;
if(newVal <= estoqueProduto){
document.getElementById("quantidade").value = newVal;
divUpd.text(newVal);
}
});
$('.value-minus1').on('click', function(){
var divUpd = $(this).parent().find('.value1'), newVal = parseInt(divUpd.text(), 10)-1;
if(newVal>=1){
divUpd.text(newVal);
document.getElementById("quantidade").value = newVal;
}
});
So far so good, the problem is that when selecting the value 3 and then the value 2, the value 3 continues to appear. I would like that when changing the value of the stock, the quantity number returns to the number 1.
Thank you Jessika.
– user24136