1
I have a textbox, and two buttons more and less, I want to decrease to zero, I managed to do but I can not decrease of 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 the logic to start from zero and it won’t.
this form I showed, is applied to start from 1, and decrease to 1, as would be the correction to start from 0, and decrease to zero?
– War Lock
Replacing where you have 0 with -1 and 1 with 0 does not solve no?
– Felipe Avelar