Skip to content
Advertisement

Number input min attribute not working with floats

With the below HTML, when I type the value 3 in the input and click on submit, Chrome (at least) shows the following error in a popup:

JavaScript

This doesn’t make sense. I’ve set the minimum value to be 0.0001 and I’m entering 3 which is greater than 0.0001.

JavaScript
JavaScript

Advertisement

Answer

The default value for the step attribute is 1, and since you’ve a min applied on your input, there’s no integral n such that min + n * step (0.0001 + n * 1) equals 3.

You can change the step to 0.0001 or any.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement