A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: using the For loop ?

  1. #1
    Registered User
    Join Date
    Dec 2000
    Posts
    144
    I wanted to use a For loop to have only those textfields be included in the summation that have user input in them.

    for example:

    I have 30 input fields and I want to have their total put into another field, the problem is that some of these fields will not have user input in them and therefore I don't want to include them in my summation.

    If someone could help me on this that would be great
    Thanks
    Jason

  2. #2
    Junior Member
    Join Date
    Apr 2000
    Posts
    17

    Summation

    First thing that comes to mind is something like this:

    set total_sums to be the number of text entries, 30 say.

    name your text boxes something like entry1, entry2, entry3, etc. (If you created an array, you could just call the text fields whatever you wanted and reference their names in an array... like sum_array("stuff","more stuff"). )

    finally, your summation.


    for (sum_loop = 1; sum_loop <= _root.total_sums; sum_loop++){
    // if statement to ignore empty fields
    if (_root["entry" + sum_loop] != null){
    _root.summation += Number(_root["entry" + sum_loop]);
    }
    }

    This will likely need some debugging, but it gives you the idea. Also, make sure that before you run it, you reset the variable summation so it doesn't keep adding to itself every time through. You can also make a verifier so that if someone enters a letter or a space or some other non-number, it tells them which field to fix.

    Hope this helps.

    brotherVM

  3. #3
    Registered User
    Join Date
    Dec 2000
    Posts
    144

    thanks it worked like a charm :)

    thank you very much for your help,

    your code worked perfect the first time, You are a Flash Master


    thanks so much
    Jason

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