Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts

    document.autoSum question

    I have a form with text boxes that hold formatted currency numbers such as 234.50, 34.50, 1,234.78. They update real time when the QTY is entered.

    I also have a SUB-TOTAL and TOTAL box's that instantly update with the total from the above text boxes. Everything works fine as long as there is no commas in the numbers, like 34.50 or 34.77 and so on. BUT if a number with a comma like 12,345.99 shows up then I get NaN in the SUB-TOTAL and TOTAL box's. The commas screw everything up.

    I am using document.autoSum and assume that autoSum does not recognize commas as a number. What can I replace document.autoSum with to add numbers with commas?

    Thanks
    Last edited by Len Whistler; 10-22-2005 at 06:44 AM.
    Leonard Whistler

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    You can strip the commas using a regular expression

    theNumber=theNumber.replace(/,/g,"")


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •