11 Replies Latest reply on Sep 25, 2009 1:42 AM by try67

    Order form total field

    Mel Wood Level 1



      wondering if someone could help me; I'm creating an interactive order form with over 100 products and I'm left to get the total fileds working properly. I've got so far and for some reason I can't figure out why it's not working for me.


      I've put some custom calculation script on the 'total field', but it's doesn't seem to be doing anything. Here's the code:


      var subEXcost = 0;


      for (i = 1; i < 110; i++){
          subEXcost = (this.getField("exCost"+i).value * this.getField("Q"+i).value);


      event.value = subEXcost;



      I've read somewhere on here that the fields this loop uses need to be named "exCost.", "Q." etc - apparently you need the positioning of the '.' - is this true?! As you can see above I've not put this in yet as if this is true, I will need to go through renaming all 270+ fields! I don't really want to do this unless I know it's meant to be like this? So can anyone answer this for me?


      The order is likely to grow with products so it will need to be a loop to calculate the totals - as there is ex VAT, inc VAT and total including p&p.


      Anyone able to help?! I've also attached the PDF file for you to look at.


      Thanks in advance

        • 1. Re: Order form total field
          Bernd Alheit Adobe Community Professional & MVP

          Use something like this:

          subEXcost = subEXcost + this.getField("exCost"+i).value * this.getField("Q"+i).value;

          • 2. Re: Order form total field
            Mel Wood Level 1

            Hi Many thanks for your speedy reply!


            I've tried what you suggested and still no joy, but I can't understand why, as it should work fine. I've just changed the variable name as the field name itself was 'SUBexCost', in case this was causing conflict, but it still doesn't work.Attached you will see.


            I've thought that perhaps the loop is breaking, so I've re-checked all the numers in the fileds names, but couldn't see anything obvious or any numbers missing. Then again I have been looking at this form for a couple of hours now.


            Any ideas on the dot ( '.' ) syntax and whether that is true?


            Cheers, Mel.

            • 3. Re: Order form total field
              gkaiseril MVP & Adobe Community Professional

              You have to use a consistant method for naming your fields. Some fields have the '.' and others do not.

              • 4. Re: Order form total field
                Mel Wood Level 1

                Hi, thanks.


                The naming convention was the consistant up until a point when I read that you need a '.' syntax (?!) - does anyone know if this is true?


                Attached is a version with Bernd Alheit's suggestion and with all the naming of the fields being consistant. It's still not working for me though after doing this and I'm stuck as to why, because I think it should work. I've also tried writing the calcualting line of code in the same manner that Bernd Alheit suggests before I came on here, and it wouldn't work then.


                As with any coding, it must be something to which I have done, but I can't see it anywhere


                Any ideas? Thanks for helping me



                • 5. Re: Order form total field
                  Bernd Alheit Adobe Community Professional & MVP

                  Look at the error messages in the JavaScript Debugger. Some fields doesn't exists.

                  • 6. Re: Order form total field
                    Mel Wood Level 1



                    Do I need to rename all the 'Q' fileds for the calculation to work? I wouldn't have thought the length of a fileds name would have prevented a calculation from working.


                    Or is it because all the fields start at '0'?

                    • 7. Re: Order form total field
                      Bernd Alheit Adobe Community Professional & MVP

                      You don't need rename the fields. In your calculation you access the fields from Q1 until Q109. Some of this fields doesn't exists, e.g. field Q86. You can see all fields in the navigation panel 'Fields'.

                      • 8. Re: Order form total field
                        Mel Wood Level 1

                        ok, I've gone away and done some on work on this, but still no joy


                        I've corrected missing fields, I've now changed the code in the loop and I'm getting to a point of complete loss.


                        Here's my code:


                        for (i = 1; i < 110; i++){
                            var exPrice = this.getField("exCost"+i);
                            var qnty = this.getField("Q"+i);
                            event.value = exPrice.value * qnty.value;



                        I just keep getting an error in the debugger console saying that both 'exCost' and 'Q' have no properties.


                        I'm now starting to wonder if my for loop can't be executed from the custom calculation script of a text field?!


                        I can't find any other examples of a loop being used to calculate a 'total' field to help me out either, I can only find examples of more basic methods.


                        Please somebody help me.


                        I've learnt alot from people's help so far.

                        • 9. Re: Order form total field
                          try67 MVP & Adobe Community Professional

                          Your loop keeps overwriting the event.value.

                          You need to either use event.value += exPrice.value * qnty.value;

                          or use a variable that will calcualte the total value and the apply it to event.value, like so:


                          total = 0;

                          for (i = 1; i < 110; i++) {

                          console.println("Getting fields number: " + i); //for debugging purposes

                          var exPrice = this.getField("exCost"+i);
                          var qnty = this.getField("Q"+i);


                          if (exPrice!=null && qnty!=null) // make sure the fields actually exist

                               total += exPrice.value * qnty.value;


                          event.value = total;


                          Also, this should probably be a custom caluclation script.

                          • 10. Re: Order form total field
                            Mel Wood Level 1

                            Hi try67,



                            Thank you so much for your help, your suggestion worked! I did try and leave this message last night, but the Adobe site went odd on me and didn't post my message.


                            Anyway, I realised after your reply my dime bar move by putting my event in my for loop - so a big 'L' for that one! It was the if statement which fixed the issue I was having. It seems obvious now it's done, to have checked the two variables using the 'null' constant. I'm still unsure as to why the the two variables set up in the loop would return nothing in the first place though. Would you mind explaining this to me?


                            I come from a flash background, I would have expected the variables to return 'exCost1', 'exCost2' and 'Q1', 'Q2' etc.


                            Thanks once again for all your help people! Very much appreciated

                            • 11. Re: Order form total field
                              try67 MVP & Adobe Community Professional

                              If the field name you specificed does not exist, getField returns null.