7

thanks for looking my questions, I can't find the way to remove the comma with javascript. So I have problem at removing comma from page with java-script, Adding Comma for output is fine i guess, but for removing comma for value, the function is not working for me.

The source code is : http://jsfiddle.net/Q5CwM/2/

Please let me know, thanks again.

3
  • 2
    What is your question? Where are you trying to remove the comma from? Looking at your jsFiddle and there's no comma on your number output. Commented Oct 20, 2011 at 22:12
  • checkNumeric() function is removing the comma, Comma() function is adding the comma. If you see this -> jsfiddle.net/Q5CwM/1/ that page doesn't have comma at all. But I want to add comma for display. So I add the comma function and use at line 69 for adding comma. And I tried to use removing comma at line 66. When i use that removing comma function, the page is having error of NaN. Commented Oct 20, 2011 at 22:15
  • checkNumeric was removing the commas and then doing nothing with the result, thus nothing was changing. See my answer below for how to fix it. Commented Oct 20, 2011 at 22:19

1 Answer 1

6

I have no idea what your code is trying to do overall, but you can fix this function that removes commas:

function checkNumeric(objName) {
    var lstLetters = objName;
    var lstReplace = lstLetters.replace(/\,/g,'');
}

by changing it to this:

function removeCommas(str) {
    return(str.replace(/,/g,''));
}

You weren't returning the changed string from the function and I changed the name of the function and parameters to represent what it does.

str.replace returns the changed string. It does not change the string you started with so in order to do something with the result of the replacement, you have to either return that from the function or assign it to some other string. As you had it, nothing was happening with the replaced string so the function did nothing.

Sign up to request clarification or add additional context in comments.

1 Comment

...and change your calls to checkNumeric to call removeCommas instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.