A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: getting sum of input text fields

  1. #1
    Member
    Join Date
    Feb 2003
    Location
    Calgary, Alberta, Canada
    Posts
    91

    getting sum of input text fields

    Hello I have 3 input text fields and one dynamic one. When i click i want it to display the total of the 3. right now im getting the 3 numbers in sequence
    ex.
    2+2+2 = 222
    i need it to say 6
    thnx
    on (release) {
    myTot_var = h1_var+h2_var+h3_var;
    }

  2. #2
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    Use parseInt to make the textfield values be interpreted as numbers instead of strings:
    code:
    myTot_var = parseInt(h1_var)+parseInt(h2_var)+parseInt(h3_var)


    If they are floating points, use parseFloat. You can also use:
    code:
    new Number(h1_var)


  3. #3
    Member
    Join Date
    Feb 2003
    Location
    Calgary, Alberta, Canada
    Posts
    91
    thanks for the respone Buddy!
    I tried the code and now im getting
    NaN in the dynamic field
    And one more question
    what actions will i need to reset the fields to 0

  4. #4
    Junior Member
    Join Date
    Jul 2009
    Posts
    5
    How did you solved the NaN problem ??? Thanks.

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