HTML input type="number" still returning a string when accessed from javascript

Sainath S.R picture Sainath S.R · Mar 4, 2016 · Viewed 35.8k times · Source

I'm new to javascript , I'm trying learning how functions etc in JS and trying to add 2 numbers

If I remove the parseInt() the value is treated as a string only , then what is the point of using <input type="number"> ?please explain to me. what field to use for getting input as a number?

Answer

Arno Chauveau picture Arno Chauveau · Mar 4, 2016

It's normal you get a string.

The purpose of the number type is that mobile browsers use this for showing the right keyboards and some browsers use this for validation purposes. For example the email type will show a keyboard with the @ and '.' on the keyboard and number will show a numeric keyboard.