Why can not I enter 500 in an HTML5 number field?

advertisements

I keep getting strange unexpected validation errors with my HTML5 number field. This is my HTML code:

<input type="number" name="width" maxlength="5" placeholder="Width" value="733.95591182365" />&nbsp;Width<br />

When I enter 500 and submit the form, I receive the error: "Please enter a valid value. The two nearest valid values are 499.95591182365 and 500.95591182365."

I've solved the problem. The problem was this value="733.95591182365". I've altered my PHP code to round decimals to integers so that only integers can be echoed into the number field. Now I only receive errors when decimals are entered, which is OK.


You need to have step="any" as an attribute when working with type="number"

<form>
  <input step="any" type="number" name="width" maxlength="5" placeholder="Width" value="733.95591182365" />
</form>