Link to home
Start Free TrialLog in
Avatar of Sheldon Livingston
Sheldon LivingstonFlag for United States of America

asked on

How to replace comma with JavaScript

I need to remove the comma from Rent (see pic). Is there a way to do this? I tried using JS.

var rent = document.getElementById("txtRent").value;
rent.replace(/,/g,'');
alert(rent);

Open in new window

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why should that work when your control as a number format active?
var rent = document.getElementById("txtRent").value;
rent = rent.replace(/,/g,''); // set it again !
alert(rent);

Open in new window


or :

var rent = document.getElementById("txtRent").value;
alert(rent.replace(/,/g,''));

Open in new window

Avatar of Anwar Saiah
Anwar Saiah

It seems like your input is defined as number, and I presume there's a good reason for that, so what I would do is make input hidden, take it's value, turn it to text, and then get rid of the comma if it's still there, feed the value to another input that is defined as text.