luissimo luissimo - 11 months ago 102
HTML Question

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?

Answer Source

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

$(this).val($(this).val().replace(/,/g, '.'));