I have a text field with little underscores as (_________)
. How do I use JavaScript to make these dashes to be replaced by the input number upon typing? (48721____)
As I type, I want the underscore to be replaced with the number I type. How do I achieve this?
Replace underscores on typing number input in JavaScript
164 Views Asked by Fuad Mammadov At
2
There are 2 best solutions below
0

I think it's more of a CSS/HTML problem than a javascript problem.
For insertion you can use javascript like this
var input = document.querySelector('input');
input.addEventListener('keypress', function(){
var s = this.selectionStart;
this.value = this.value.substr(0, s) + this.value.substr(s + 1);
this.selectionEnd = s;
}, false);
Here is a working example https://codepen.io/jteck13/pen/RwYoeMp
Hope I could help
You can do something like this:
Tell me if this solves your problem.