Replace comma with dot when typing decimals in input - Javascript

How can I replace comma with dot when typing decimals in input field, by using javascript function ?
24 Mar 2020 at 06:15 PM
0pnshow more

To replace comma with dot while typing or inserting of the number into input field, you can use Javascript solution with onKeyUp and onBlur event:

<script type="text/javascript">

function replaceComma(i) {
var val = document.getElementById(i).value;
if (val.match(/\,/)) {
val = val.replace(/\,/g, '.');


<input type='text' id='amount' onKeyUp="javascript: replaceComma('amount'); " onBlur="javascript: replaceComma('amount'); " />

27 Mar 2020 at 03:26 PM
0pnshow more
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook & Twitter
2021 AnswerTabsTermsContact us