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

    0  

    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.

Reply
  • Verified Answer

    0  

    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.

Children