Idrees Samim
Idrees Samim

Reputation: 463

input form number with 3 decimals bug html

I want to enter numbers in an input form and display the entered number when user press Enter.

<input type="number"  onKeyPress="if (event.keyCode == 13) { myFunction(this); }"></input>
<p id="demo"></p>

function myFunction(that) {
       document.getElementById("demo").innerHTML = that.value;
   }

Everything works correctly except when I enter a number with exactly 3 decimals (E.g. 0.123). The bug occurs only with a number that has 3 decimals. It's absolutely non-sense.

Here is a link for a jsfiddle:

http://jsfiddle.net/ckfnd445/2/

Upvotes: 1

Views: 77

Answers (1)

Serhiy Chupryk
Serhiy Chupryk

Reputation: 438

What I discovered and that may help you. If your localization is not en-us you may have an issue :)

So to fix your input control problem try to specify at least lang attribute for the control, like this:

<input type="number" lang="en" onKeyPress="if (event.keyCode == 13) { myFunction(this); }"></input>

Also you may want to specify step="any" to let your browser validate the control correctly (because default step is 1). Or you may want to disable validation for it

Upvotes: 2

Related Questions