I am in need of some code that removes commas from a string. I currently have a variety of numbers in the number_format() for PHP. I use Jquery to post certain things to a update page and I need the commas removed from a class.
for instance here is some code.
<span class="money">1,234,567</span>
I want the value of the code I post to be 1234567 instead of 1,234,567. I would like to use Jquery if that's possible.
Thanks
Sometimes, we may need to remove the comma, semicolon, colon etc from the string in our jquery code. So at that time we can do this simply remove comma by using js replace(). Jquery replace() through we can easily replace the comma into empty string on that way comma will be remove from the jquery string.
This is a clean way to get rid of the commas in one line, without loops. var cleanNumber = $("#selector"). val(). split(",").
What you can also do is just send the array as an array! var formUrl = 'explorer. php'; var $form = $("<form action='"+ formUrl +"' method='post'></form>") . append("<input type='hidden' name='form_submitted' value='true'>") .
Use a regex with the g flag instead of a string: . replace(/,/g, "") .
replace
var noCommas = $('.money').text().replace(/,/g, ''),
asANumber = +noCommas;
This is a clean way to get rid of the commas in one line, without loops.
var cleanNumber = $("#selector").val().split(",").join("");
Hope can help u!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With