I couldn't find any answer to my problem. I have an input with type="number" and I want the number to automatically add dots to it when it goes up to 1000. So instead of 1000 it should output 1.000, is there a possibility to do that? Like adding some attribute to the input?
Asked
Active
Viewed 9,984 times
3
-
use javascript for this. – Neil Sep 24 '15 at 10:49
-
what did you tried so far?? Add codes in our question – Rohit Kumar Sep 24 '15 at 10:49
-
There are some different solutions shown here: http://stackoverflow.com/questions/5963158/html5-form-input-pattern-currency-format – humer Sep 24 '15 at 10:55
1 Answers
2
You can use Javascript to add them. Try this plunker: http://plnkr.co/edit/rsTCO8hmZUSEtrvpuWE6?p=preview
If you just need one dot a simple way would be this:
<input type="number" onkeyup="oneDot(this)"/>
And in JS:
function oneDot(input) {
var value = input.value,
value = value.split('.').join('');
if (value.length > 3) {
value = value.substring(0, value.length - 3) + '.' + value.substring(value.length - 3, value.length);
}
input.value = value;
}

arsuceno
- 46
- 3