Hodorogea Alexandru Hodorogea Alexandru - 4 months ago 12
Javascript Question

Replace comma with dot in a input Javascript

How to replace automatically all commas from a input with dots?

I have this input:

<input type="text" id="test" onChange="testfunc()"> </input>


And this is my work so far:

function testfunc() {
var testnr = document.getElementById("test").value;
testnr = testnr.replace(/,/g, '.');
}

Answer

testnr will store the value, so this testnr = testnr.replace(/,/g, '.'); will only change the value without changing the ÌNPUT, please try this:

<input type="text" id="test" onchange="this.value = this.value.replace(/,/g, '.')"/>
Comments