Can someone help me figuring out why the following jQuery code doesn't work? I want to return a integer from an user input.
var test = parseInt($("#testid"));
Thank you & bye!
var test = parseInt($("#testid").val(), 10);
You have to tell it you want the value
of the input you are targeting.
And also, always provide the second argument (radix) to parseInt
. It tries to be too clever and autodetect it if not provided and can lead to unexpected results.
Providing 10
assumes you are wanting a base 10 number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With