Home > Domino Tips > Developer > JavaScript > Remove commas from dollar amounts in JavaScript using a split
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVASCRIPT

Remove commas from dollar amounts in JavaScript using a split


Mike Parman
09.26.2006
Rating: -2.67- (out of 5)


Lotus Notes and Domino tips, tutorials and how-to articles
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


VIEW MEMBER FEEDACK TO THIS TIP

Have you ever tried to add up multiple fields with JavaScript, only to find out that the client entered a comma to separate thousands and millions? This causes JavaScript to drop all of the digits after the comma. You can use the split command to extract the commas prior to adding the fields together.

Add the removeComma function to the JavaScript Header section of your form, then add the call to the function, onto the onBlur section. Now, when the client moves from one field to another, all commas will be removed from the field.

function removeComma(num) {
var temp1 = 0;
var xarray = num.split(",");
if ( xarray[2] != null ) {
   temp1 = xarray[0]+xarray[1]
+xarray[2]; return temp1 } 
else if ( xarray[1] != null ) {
          temp1 = xarray[0]
+xarray[1]; return temp1}
       else
{temp1 = xarray[0]; return temp1 }         
}

MEMBER FEEDBACK TO THIS TIP

I've found this works as well.

function removeComma(num) {
    var temp1 = num;
    for (i=1;i<3;i++) {  
// pick limit high enough to find all possible
commas
    temp1 = temp1.replace(",","");
    }
    return temp1;
}

—Michael N.

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • Learning Guide: JavaScript development
  • FAQ: JavaScript advice

    This tip was submitted to the SearchDomino.com tip library by member Mike Parman. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

    Rate this Tip
    To rate tips, you must be a member of SearchDomino.com.
    Register now to start rating these tips. Log in if you are already a member.




    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


    RELATED CONTENT
    JavaScript for Lotus Notes Domino
    How to create dynamic JavaScript in Notes Domino without formulas
    Trap an attachment path via the Domino file upload control field
    Converting Lotus Notes views to XML documents using JavaScript
    Mimic Lotus Notes Domino application functionality on the Web
    Prevent errors on iFramed pages with JavaScript
    Top 10 Lotus Notes Domino programming and development tips of 2007
    How to add keyboard functionality for Lotus Notes documents
    Validate Lotus Notes Domino fields using JavaScript
    How to support Flash objects in any Web browser for a Lotus Notes Domino application
    How to validate Lotus Notes forms on a Domino server without losing entered data

    JavaScript
    How to create dynamic JavaScript in Notes Domino without formulas
    Trap an attachment path via the Domino file upload control field
    Converting Lotus Notes views to XML documents using JavaScript
    Prevent errors on iFramed pages with JavaScript
    How to add keyboard functionality for Lotus Notes documents
    Validate Lotus Notes Domino fields using JavaScript
    How to support Flash objects in any Web browser for a Lotus Notes Domino application
    How to validate Lotus Notes forms on a Domino server without losing entered data
    Ajax code equivalent of the @DBColumn formula for Lotus Notes
    A bevy of Notes/Domino development tips

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary

    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
    HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




    All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts