I am trying to format a number input by the user into currency using javascript. This works fine on <input type="text" />
. However, on <input type="number" />
I cannot seem to be able to set the value to anything that contains non-numeric values. The following fiddle shows my problem
Is there anyway for me to set the value to something like $125.00
?
I want to use <input type="number" />
so mobile devices know to bring up a keyboard for number input.
Add step="0.01"
to the <input type="number" />
parameters:
<input type="number" min="0.01" step="0.01" max="2500" value="25.67" />
Demo: http://jsfiddle.net/uzbjve2u/
But the Dollar sign must stay outside the textbox... every non-numeric or separator charachter will be cropped automatically.
Otherwise you could use a classic textbox, like described here.