I\'m using jQuery to retrieve a value submitted by an input button. The value is supposed to be an integer. I want to increment it by one and display it.
//
There is a parseInt method for that or Number constructor.
var count = parseInt(countUp, 10) + 1;
See w3schools webpage for parseInt.
To convert strValue
into an integer, either use:
parseInt(strValue, 10);
or the unary +
operator.
+strValue
Note the radix parameter to parseInt
because a leading 0 would cause parseInt
to assume that the input was in octal, and an input of 010
would give the value of 8 instead of 10
Use parseInt as in: var count = parseInt($("#"+countUp).val(), 10) + 1;
or the +
operator as in var count = +$("#"+countUp).val() + 1;
parseInt( $("#"+countUp).val() , 10 )