Javascript for Formatting Currency Values
634176Sep 24 2008 — edited Sep 24 2008I have a textbox, P1_TOTAL_AMT, which requires the user to enter an amount value. I am looking to use the “onBlur” javascript event to add a format mask to the textbox, so that it displays a “$” sign, and formats the number with commas in appropriate places.
For example, if the user enters “223645.12132”, after the user moves on to the next form field, the P1_TOTAL_AMT should read “$2,23,645.12132”.
I have created a script which uses the "split()" function to separate the part before decimal point and the part after. Somehow I'm messing up with the code required to insert commas! I wrote a script but am getting commas incorrectly.
For example, in my code, when the user enters "10000.236", he gets an output of "$100,00.,236", which is incorrect.
Please do not consider the accuracy of data (i know that in an amount, more than 100 cents must add a dollar, but as per user requirements we don't have to handle that. we have to let the user enter whatever "cents" value they want). Also, I need to use javascript and create a reusable script for other applications other than Apex (so can't use any built in format masks)
Can someone provide an example for such a script?
Any help is greatly appreciated.