I have more than two fields that is related to currency and I need to format it.I have written the format function already but as of now I can pass only one field/ID i.e. Income to the JS function. How can I pass multiple ID's to this common function so that I can format my fields using this common function.
I want to pass income and trade value that I'm getting through document.getElementById to formatCurrency function? How to pass multiple ID's to a function and set this to the ID? I tried setting the below way
$("#Income").val(formatCurrency($("#Income").val()));
but didnt work
function formatCurrency(amt){
amt = amt.replace("$", "");
if(amt && amt.split(".").length <= 2)
{
var formatter = new Intl.NumberFormat('en-US',
{
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
});
amt = formatter.format(amt);
}
document.getElementById("Income").innerHTML=amt;
//document.getElementById("Trade").innerHTML=amt;
}
formatCurrency(document.getElementById("Income").innerHTML);
//formatCurrency(document.getElementById("Trade").innerHTML);
If Income=8000 output should be $8000.00 and If Trade=900 output should be $900.00 I am able to achieve only for Income and not for trade as I am unable to pass Trade to the formatCurrency.
formatCurrency("Income")and inside the method read the text and output it