I format numbers using jqnumformatter plugin. Everything is fine with that but I'm having problems on removing the commas. I used .each() to loop through all the inputs which has commas on it. But in this case I need to click on the next button twice so that all the commas on the numbers will be removed.
<script>
$(function(){
$("#next").click(function(){//unformats the numbers
$("input[data-toformat=format]").each(function(){
var formatted = $(this).val();
var unformatted = formatted.replace(",", "");
$(this).val(unformatted);
});
});
});
</script>
<input type="text" id="num" data-toformat="format" autofocus/>
<input type="text" id="num2" data-toformat="format" />
<input type="button" id="next" value="next">
<input type="button" id="back" value="back">
Do you have a better way on doing this?It really fails to unformat the numbers all at once if I have 2 or more commas on each of the numbers.