+ 1

How to get input value as a number in javascript?

input value return as a string.

12th May 2017, 10:46 AM
Mohamed Kalith
Mohamed Kalith - avatar
3 Answers
+ 4
Number() will auto-cast float or int, but you can also use parseInt() or parseFloat() if you want to force to a specific type ^^
12th May 2017, 2:10 PM
visph
visph - avatar
+ 1
var yourString = "12"; var number = Number(yourString); Jquery example with input: var value = Number($("input").val());
12th May 2017, 10:51 AM
tehzarathustra
0
var num = 12;
12th May 2017, 10:56 AM
CalviŐ˛
CalviŐ˛ - avatar