8 Replies Latest reply on Oct 29, 2009 3:33 AM by Mel Wood

    complicated order form

    Mel Wood Level 1

      Hello,

       

      I'm working on quite a complicated order form and I've hit a snag. I've been on here before and my loop question was answered. However, the order form has had to change due how we promote offers on certain products. Basically we have sections like maths, science, puppets etc. we have offers running like, buy any science resource and get X half price.

       

      So I've put together this new order form - see attached.

       

      I've contained the custom calculation script in the titles of the sections. The one I'm working on is in the 'Maths' title.

       

      The offer I'm trying to get working is: buy any Concept Cartoons Maths item and get any Maths on Fire item half price.

       

      so my code at the moment looks like this:

       

       

       

      var showPromo = false;
      var hidePromo = false;


      totalCCM = 0;


      var MoFoffer = this.getField("Q6.0");
      var MoFoffer2 = this.getField("Q6.1");
      var MoForig = this.getField("Q1.11");
      var MoForig2 = this.getField("Q1.12");

       


      for (i = 1; i <= 10; i++){
          var allCCM = this.getField("Q1."+i);

       

          if (allCCM!=null)
              totalCCM += allCCM.value;
       
      }


          if ((totalCCM.value < 100)&&(totalCCM.value > 0))
              var showPromo = true;
          else if(totalCCM.value == 0)
              var showPromo = false;
              MoFoffer.value = 0;

       

          if ((totalCCM.value < 100)&&(totalCCM.value > 0))
              var showPromo = true;
          else if(totalCCM.value == 0)
              var showPromo = false;
              MoFoffer.value = 0;
         
          if(showPromo)
              EnableBorderFieldFromGray("Q6.0");
          else
              DisableBorderFieldToGray("Q6.0");

       

          if ((totalCCM.value < 100)&&(totalCCM.value > 0))
              var hidePromo = true;
          else if(totalCCM.value == 0)
              var hidePromo = false;
         
          if ((totalCCM.value < 100)&&(totalCCM.value > 0))
              MoForig.value = 0;
         
          if(hidePromo)   
              DisableBorderFieldToGray("Q1.11");
          else
              EnableBorderFieldFromGray("Q1.11");

       

       

       

      There is also a document function which is called to effectively 'grey out' and disable the target fields. Hence the 'showPromo' and 'hidePromo' booleans.

       

      So what should happen is that when someone enters a number higher than '0' in a quantity field of the fields contained in my loop, it 'greys out', disables the quantity fields and sets the value back to '0' of the full priced product fields and enables fields at the end of the order form for the user to have the half price costs of the items on offer.

       

      Hope that makes sense!?

       

      I set my calculation order up to be the correct order and this was working when tested with variables set up with 'this.getField'. This has only stopped working since I introduced the loop, to be able to select several fields as opposed to one filed.

       

      I have a feeling that the problem lies with the 'totalCCM' variable, perhaps I can't call this variable outside of the loop? Or perhaps, the loop is not working? The loop is meant to work from field names 'Q1.1' through to 'Q1.10' (all the Concept Cartoons Maths products).

       

      Any help would greatly appreciated, thanks to people in advance!

       

      Mel.

        • 1. Re: complicated order form
          try67 MVP & Adobe Community Professional

          The loop works fine. I think the problem is that you're not placing { } around sections that need to be run together, especially after some of the else statements.

          • 2. Re: complicated order form
            Mel Wood Level 1

            Ok, I've been looking at this for most of this morning, give us another clue?

             

            Also whilst running the debugger, I've noticed something odd about the loop. Basically I want to find fields 'Q1.' and then in the loop create an integer which starts from 1 and counts to 10. So it would call fields: Q1.1, Q1.2, Q1.3 etc and stop at Q1.10. These are all theCCmaths items on the form. This is possible right? Only when I enter a number like 4 in field Q1.10 it's like the loop is counting it in multiples of 2, so I get 8.

             

            Little bit baffled as the loop integer is only set to be less or equals to 10, meaning it should stop at 10 and go no higher.

             

            I think the problem is with the operator I'm using to calculate the 'totalCCM' var. But surely using += it should be only adding a sum like this:

             

            0 + X = ?

             

            X being the value inputted in any field from Q1.1 - Q1.10

             

            I'm getting a bit lost now. Anyone able to help out?

             

            I understand the {} issue that you've mentioned, but I think there are other problems stopping this from working. As before I introduced the loop I had this code working. The previous code looked like this:

             

             

             

            var showPromo = false;
            var hidePromo = false;


            totalCCM = this.getField("Q1.1");;


            var MoFoffer = this.getField("Q6.0");
            var MoFoffer2 = this.getField("Q6.1");
            var MoForig = this.getField("Q1.11");
            var MoForig2 = this.getField("Q1.12");

             


            if ((totalCCM.value < 100)&&(totalCCM.value > 0))
                 var showPromo = true;

             

            else if(totalCCM.value == 0)
                 var showPromo = false;
                 MoFoffer.value = 0;

             

             

            if ((totalCCM.value < 100)&&(totalCCM.value > 0))
                  var showPromo = true;
            else if(totalCCM.value == 0)
                  var showPromo = false;
                  MoFoffer.value = 0;

             

             

            if ((totalCCM.value < 100)&&(totalCCM.value > 0))
                  var showPromo = true;
            else if(totalCCM.value == 0)
                   var showPromo = false;
                  MoFoffer.value = 0;

             


            if(showPromo)
                 EnableBorderFieldFromGray("Q6.0");
            else
                 DisableBorderFieldToGray("Q6.0");

             

             

            if ((totalCCM.value < 100)&&(totalCCM.value > 0))
                  var hidePromo = true;
            else if(totalCCM.value == 0)
                  var hidePromo = false;

             


            if ((totalCCM.value < 100)&&(totalCCM.value > 0))
                  MoForig.value = 0;  

             

            if(hidePromo)   
                 DisableBorderFieldToGray("Q1.11");
            else
                EnableBorderFieldFromGray("Q1.11");

             

             

             

             

            It does work a treat, have a look at the attached file to see it working. So all I got to do if set up a loop which relates to all theCCM items (Q1.1 - Q1.10) and it's done. But it's not working out 

             

            Anyone able to help?

            • 3. Re: complicated order form
              try67 MVP & Adobe Community Professional

              What I meant mentioned earlier was regarding lines like this:

               

              else if(totalCCM.value == 0)
                   var showPromo = false;
                   MoFoffer.value = 0;

               

              From your indentation it looks like you intend that the last line will only be executed if the value of totalCCM is zero, but by using this syntax you're causing it to be executed no matter what because only the first line after the if statment is depenedent on its result.

              Here's how you should adjust it:

               

              else if(totalCCM.value == 0) {
                    var showPromo = false;
                    MoFoffer.value = 0;

              }

              • 4. Re: complicated order form
                Mel Wood Level 1

                I did think that when you mentioned it, as in Flash AS code (my main background skill) simply won't work without the {} around any lines to be executed. I'm suprised any code has worked so far in JS.

                 

                I did try this, but it still wasn't executing the code in the if..else if.. statements.

                 

                The debugger is showing that the totalCCM var value is being set to the values found in the loop, but anything after this isn't being done.

                 

                 

                 

                I will try this again and let you know how I get on. Many thanks for your help again, Try67. Really do appreciate it.

                • 5. Re: complicated order form
                  Mel Wood Level 1

                  How do I run a trace in JS? I want to check the totalCCM var at different points of the code.

                   

                  Cheers, Mel.

                  • 6. Re: complicated order form
                    Mel Wood Level 1

                    This doesn't seem to work. I've even tried the if..else statements inside and outside of the loop and it still doesn't work. It's like it's getting stuck on or around this if statement, perhaps passing the variable to the next statements is the problem:

                     

                    if (allCCM!=null)
                            totalCCM += allCCM.value;

                     

                    Even though in the debugger it returns the values as typed in (well apart from the oddity of the last field - Q1.10, which seems to multiply the value).

                    • 7. Re: complicated order form
                      Mel Wood Level 1

                      Ok, figured it out.

                       

                      The 'totalCCM' var doesn't have a value property to refer to. I'm going to guess that a variable you set up doesn't automatically inherit properties to then later on call upon. Not sure if what I've said is the correct way of describing the issue I was having. Anyone who can correct are more than welcome to; I'm strong believer that you can always learn new things!

                       

                      So, I removed the .values from the code and all works spiffingly well

                       

                      I'm sure Try 67, your comments have also helped to make it all work well! So thank you so much for your time!

                       

                      Hope this thread will help others trying to work on a similar project.

                      • 8. Re: complicated order form
                        Mel Wood Level 1