I have the following function, which successfully increases the value of input type="text"
function deleteLine(arrayNumber) {
$("#line" + arrayNumber + "_quantity").val(parseInt($("#line" + arrayNumber + "_quantity").val()) + 1);
}
I’m just wondering why these don’t work instead, for a neater code:
$("#line" + arrayNumber + "_quantity").val(this + 1);
$("#line" + arrayNumber + "_quantity").val(this.value + 1);
$("#line" + arrayNumber + "_quantity").val($(this).val() + 1);
You should try like below,
Your version doesn’t work because the
thisdoesn’t refer to the textbox.Thanks @FelixKing for the unary operator.