I have a huge form with several input fields. This is a Balance and a Profit & Loss sheet, so the input text fields has to be formatted as "money". I found some nice jQuery plugin to do the formatting: accounting JS, but right now I have to call it manually on all the fields and this is not the best method I think...
How can I call the accounting.formatMoney() function on ALL the input text fields on keydown? So if there is a KeyDown or KeyUp event on the FORM or BODY, the script will find ALL the input fields and execute the script.
This is the formatting and the Javascript function I want to call on every INPUT text field:
var options = {
symbol : "",
thousand: " ",
precision : 0,
format: "%v%s"
};
var tmp = parseInt(document.getElementById('input_id').value, 10);
document.getElementById('input_id').value = accounting.formatMoney(tmp, options);
The form is sent back to BODY via AJAX, so I think the best method would be to call the function this way:
$(document).ready(function(){
$('body').on('keyup', 'input', function(e){
// collect all input fields and execute the function
});
});
Thank you very much for the help!