Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using js lib NumberFormat, download in http://www.mredkj.com/javascript/nf_api.html
- $(function(){
- //Format number for all controls $('input.only_number') onload action of page
- var arr2 = $('input.only_number');
- var arrNumber2 = new Array();
- for(var i = 0; i< arr2.length;i++){
- arrNumber2[i] = formatMoney($(arr2[i]).val());
- $(arr2[i]).val(arrNumber2[i]);
- }
- //Format number when onkeyup action
- $('input.only_number').keyup(function(){
- //To format number separator by ","
- num = $(this).val();
- num = new NumberFormat(num);
- num.setPlaces('0', false);
- num = num.toFormatted();
- $(this).val(num);
- //Save number to hidden input >> It helps you to post data to the server properly format
- save_num = new NumberFormat(num);
- save_num = save_num.toUnformatted();
- $(this).next().val(save_num);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment