Hodorogea Alexandru Hodorogea Alexandru - 1 year ago 92
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 Source

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, '.')"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download