A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Adding multiple Numbers

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    1

    Adding multiple Numbers

    Hi there,

    I'm building a calculator of sorts and have about 7 input text boxes (input text chosen) that users can enter numbers. At the bottom I have a calculate button that adds all of the numbers users have input into the boxes. The answer goes into a dynamic text box. It all works fine expect if a user does not enter in a number in one or more of the boxes. In other words, users would have to input a number in each box for it to work, I don't want that.

    Here is the code on the calculate button:

    TransportationTotal = Number(Limo) + Number(SUV) + Number(HorseCarriage) + Number(Boat) + Number(Helicopter) + Number(LuxuryCoach) + Number(LuxuryCar) + Number(TransportationGuests);
    }

    whereas the names in brackets are the var assigned names. Any ideas? Do I need to declare the var's beforehand? Tired this and did not work.

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    you could have make code that if the text fields have nothing than the code will give them a value like:
    if (Limo == ""){
    Limo = "0";
    }
    Then you wouldn't have to change your above code.
    .

  3. #3
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    you could also start out with 0's in your text fields...

    I would also check to see if textField != "" before adding it to the total..

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center