I have a textbox , and two more and less buttons, I want to decrease to zero, I managed to do but I can not decrease from 1:
HTML
<asp:TextBox ID="txtAcrescimo" type="number" CssClass="form-control" MaxLength="18"
runat="server" onblur="javascript:defineQuantidade();"></asp:TextBox>
<div style="display: inline-block; margin-right:10px;">
<input id="aumentaAcrescimo" type="button" onclick="aumentaAcrescimo()" style="width: 35px; margin-left:10px; height: 35px" value="+" />
<td>
<input id="diminuiAcrescimo" type="button" style="width: 35px; height:35px " value="-" />
</div>
JS
$("#txtAcrescimo").val(1);
//aumenta acrescimo
$("#aumentaAcrescimo").click(function () {
var acrescimo = parseInt($("#txtAcrescimo").val());
if (acrescimo <= 0) {
$("#txtAcrescimo").val(1);
} else {
acrescimo++;
}
$("#txtAcrescimo").val(acrescimo);
});
$("#diminuiAcrescimo").click(function () {
var acrescimo = parseInt($("#txtAcrescimo").val());
if (acrescimo <= 0) {
$("#txtAcrescimo").val(1);
} else if(acrescimo > 1) {
acrescimo--;
}
$("#txtAcrescimo").val(acrescimo);
});
I got it that way and it worked, but it starts at 1, I tried to apply logic to start from scratch and it will not.