Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace comma with a dot while typing jQuery

Hi i want to replace a comma with a dot while typing in a text input field using jQuery. I have this code right now;

$(document).on('change', '.unitprice', function() {
  $(this).val().replace(/,/g, '.');
});

The class of the input field is unitprice

But it's not working.. And i can't seem to find the correct answer on google. Anybody has an idea on how to accomplish this?

like image 304
luissimo Avatar asked Oct 27 '25 14:10

luissimo


1 Answers

You're just changing the variable and not writing it back.

$(this).val($(this).val().replace(/,/g, '.'));
like image 157
Lazar Ljubenović Avatar answered Oct 29 '25 06:10

Lazar Ljubenović



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!