Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parseInt with jQuery [closed]

Tags:

jquery

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!

like image 848
Floppy88 Avatar asked Mar 19 '12 18:03

Floppy88


1 Answers

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.

like image 139
jondavidjohn Avatar answered Sep 21 '22 20:09

jondavidjohn