How to replace dot by comma in javascript ?

Hello, 

I have to replace dot by comma in numerics fields but I can't manage to do it.

I add a javascript in a form action, on submit : 

var fieldtxt = GetFieldValue("My field name").replace(".",",");

console.log(fieldtxt);

But I have an error that tells me that "replace" is not found.

How can I do this ? 

Any idea ?
Thank you for helping.

Parents
  • Verified Answer

    Hi Cindy, if I understand your situation correctly, then GetFieldValue would be returning a number and "replace" is not a method for a number. I would suggest something like the following so that it can be more easily stepped through in the browser Developer Tools.

    var fieldnumber = GetFieldValue("My field name");

    var fieldtxt = fieldnumber.toString();

    var updatedtext = fieldtxt.replace(".",",");

     

    It is a curious use case - if this is due to locale that you would want to do this, there could be other approaches.

  • Hi

    That's exactly it.

    We're using the local French and when some of our users write "0.531" it becomes "531" on submit ! It's a big problem. And until the problem is resolved, I'm looking for something to correct it.

    Thanks for your answer, i'm trying it.

Reply Children