Search This Blog

Monday, April 23, 2018

[SOLVED] - How to Enter Floating-Point/Decimal Numbers in HTML5 Forms

If you have a form where you have declare a input type as below:
 <input type="number" name="quantity" min="1" max="5">  

Now if you enter a floating-point/decimal value like '2.1' and try to process your form then you will get the following error message:

"Please enter a valid value. The two nearest valid values are 2 and 3."

How to Enter Floating-Point/Decimal Values in HTML5 Forms
Click on image to enlarge
Solution:
To solve this just add
step="any"
to your form. So, your input code should be as follows:
 <input type="number" name="quantity" min="1" max="5" step="any">  

Now, you should be able to enter decimal/floating-point values and process them without any hassle.

No comments:

Post a Comment

Thank you for your Feedback!
www.evagabond.me

Top Magento Hosting:

Top 5 Posts (Weekly)