简体   繁体   中英

How to reformat an auto formatted number using JQuery

Hello Im fairly new to Javascript/JQuery. I wanted to autoformat a number while it was being inputted. I used a Jquery plugin for the same - <script src="simple.money.format.js"></script> And calling it using $('.money').simpleMoneyFormat();

I want it be reformatted when I hit a button (Save) so that the value can be saved into the database. Any help would be much appreciated.

You can use the submit event handler, the code will be called when the user hits the submit button, and before the data sent to the server

$('#your-form-id').submit(function () {
    $('.money').simpleMoneyFormat();
});

See the following fiddle: https://jsfiddle.net/EliteSystemer/wv3sxo3j/

$('button').on("click", function() {  //Submit
  var m = $('.money').val();  //Get input value
  m = m.replace(/,/g, "");  //Remove commas
  $('.money').val(m);  //Update input value
  ...send to server
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM