11 Replies Latest reply on May 20, 2010 3:19 AM by Mel Wood

    how do I get my offer pricing to work?

    Mel Wood Level 1

      Hi All,

       

      Just before you read this - how do you attach documents to messages? I know you used to be able to!? Otherwise I'll be back on here to update my question below!

       

       

      I'm working on an online order form and I'm a bit stuck after getting so far. What I'm trying to do is:

       

      • when you enter a quantity for any of the 'Concept cartoons in Maths' products, the 'Maths on Fire' products below are disabled. At the same time the 'Maths on Fire' in the Offers section becomes enabled (go to the last page to see this).
      • You then can choose your 'Maths on Fire' offer quantity.
      • If you then choose another 'Concept cartoons in Maths' product or you change the quantity of the already chosen product. The quantity you put in the 'Maths on Fire' is being reset back to '0'

       

      I of course don't want this to happen, so anyone able to help me out on this one?

       

      Thanks in advance guys!

       

      Mel.

        • 1. Re: how do I get my offer pricing to work?
          Bernd Alheit Adobe Community Professional & MVP

          Just before you read this - how do you attach documents to messages?

          File attachment is diasbled.

          • 3. Re: how do I get my offer pricing to work?
            Mel Wood Level 1

            Hi Guys,

             

            Thanks for your responses; I have already used Thom Parker's tutorials to help build the form I have so far. When the quantity in the loop of fields 'Q1.+i' has a number higher than '0' inputted then 2 normal priced items become disabled and 2 offer priced items are enabled.

             

            The issue I'm having is in the scenario of someone entering say 2 of one item contained in the loop and 1 of another item contained in the loop, then say choose 2 of the offer priced items. If their mind was to be changed from wanting only 1 item in the contained loop, so they changed the '2' value to '0', the offer priced items are resetting back to '0'. but remaining still enabled.

             

            This would suggest to me that it's somehow reading the lines of code between the 'else if' statement as there is no where else that resets the offer priced items to '0'. And maybe perhaps it's overwriting the disabling of these fields as there is still a quantity of '1' within the items contained in the loop.

             

            Here's the code:

             

             

            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 < 100)&&(totalCCM > 0)){
                    var showPromo = true;
                    var hidePromo = true;
                }
                else if(totalCCM == 0){
                    var showPromo = false;
                    var hidePromo = false;
                    MoFoffer.value = 0;
                    MoFoffer2.value = 0;
                }

             


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

             


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

             

             

            Is there some sort of event listener that could be used in acrobat scripting that checks all the fields contained in the loop? That would perhaps mean that it would check all the fields for what their values are instead of only taking into consideration the value that's just been inputted?

             

            I'm a bit hazy on this one, anyone able to help?

             

            Thanks, Mel.

             

             

            PS - bummer the attachments has been disabled! that's quite pants!

            • 4. Re: how do I get my offer pricing to work?
              try67 MVP & Adobe Community Professional

              I'm not sure this is the reason for the problem, but it might be.

              In this block of code:

              else if(totalCCM == 0){

                      var showPromo = false;

                      var hidePromo = false;

                      MoFoffer.value = 0;

                      MoFoffer2.value = 0;

                  }

               

              you use the "var" keyword which means that a new variable is created in this

              scope (within the curly brackets). As a result, the showPromo and hidePromo

              variables that you defined at the start of the script are not influenced by

              this and will always be true.

              Try the following instead:

               

              else if(totalCCM == 0){

                      showPromo = false;

                      hidePromo = false;

                      MoFoffer.value = 0;

                      MoFoffer2.value = 0;

                  }

              • 5. Re: how do I get my offer pricing to work?
                Mel Wood Level 1

                Hi Try,

                 

                Thanks for your response, I've just tried what you suggested. It doesn't appeared to have made much difference, it's still not quite behaving properly. Always good to be correct with coding practice though.

                 

                I've done a bit more testing and have noticed that it's acting odd when I use the 1st field in the loop, so field Q1.1, all the other fields can contain a value higher than '0', but if you change the value of this Q1.1 field back to '0' itself it's resetting the offer fileds back to '0' and keeping it the offer fields enabled.

                 

                Little bit puzzled why only this field seems to be doing this.

                 

                I've hosted the PDF here: http://www.millgatehouse.co.uk/resources/secret/100406/MHE-online-PO-form.pdf

                 

                The code for the script I've put in the title bars (the green ones with white text).

                • 6. Re: how do I get my offer pricing to work?
                  try67 MVP & Adobe Community Professional

                  Is there a reason you use this naming convention? Because Acrobat uses the

                  period to create "widgets", which are copies of the same field, but with

                  different styles. So all widgets with the same name (the part before the

                  period) will have the same value.

                  I can't test the PDF right now, but I would try changing the names of the

                  fields to Q1-1, Q1-2, etc.

                  • 7. Re: how do I get my offer pricing to work?
                    Mel Wood Level 1

                    There's nothing restrictive about why I use this naming convention, no. So I've just changed the naming convention, but there doesn't seem to be anything different happening. It's still acting up.

                     

                    I'm at a bit of a loss now

                     

                    Cheers, Mel.

                    • 8. Re: how do I get my offer pricing to work?
                      scottMbishop

                      I changed your code to the following and it appears to work as you desire.  It seemed that you were testing for null when the field was certainly going to be found, so I removed that.  I also removed variable declaration when an object or value was only going to be called once.  Typically I declare variables only when it is something that will get reused in the code.  showPromo and hidePromo don't need to be used or tested for as you can set the desired results at the point where you evaluate "totalCCM".  Let me know if this works for you and if there are any other scripts in the form that you would like to tweak.

                       

                      var totalCCM = 0;

                        for(i = 1; i < 11; i++) {
                        totalCCM += this.getField("Q1." + i).value;

                          if(totalCCM < 100 && totalCCM > 0) {
                          EnableBorderFieldFromGray("Q6.0");
                          EnableBorderFieldFromGray("Q6.1");
                          DisableBorderFieldToGray("Q1.11");
                          DisableBorderFieldToGray("Q1.12");
                          this.getField("Q1.11").value = this.getField("Q1.12").value = 0;
                          } else if(totalCCM == 0) {
                          DisableBorderFieldToGray("Q6.0");
                          DisableBorderFieldToGray("Q6.1");
                          EnableBorderFieldFromGray("Q1.11");
                          EnableBorderFieldFromGray("Q1.12");
                          this.getField("Q6.0").value = this.getField("Q6.1").value = 0;
                          }
                        }

                      • 9. Re: how do I get my offer pricing to work?
                        Mel Wood Level 1

                        Hi Scott,

                         

                        Thank you so much for posting a comment on this thread, I've been trying to figure this one out for a while. I tried your suggested code and it's still having the same affect I'm afraid. Which is a bit frustrating.

                         

                        It's still seems to have an issue with the first input box in the loop. If you put say the 2nd box's value to '1' and then the 1st box's value to '1' then go the offer priced section and type in the value of '1' in either of the boxes. Then go back to the Concept Cartoon in Maths section and ONLY put the 1st box in the loop value back to '0' it resets all the values in the offer priced section. Even tho the 2nd box in the loop value is set to '1'.

                         

                        Did you make chnages else where to the code in the form? Only the original priced Maths on Fire items are no longer being 'disabled'.

                         

                        Most puzzling as it only seems to be a bug with the 1st box included in the loop.

                         

                        Any further thoughts from anyone?

                         

                        Many thanks, Mel.

                        • 10. Re: how do I get my offer pricing to work?
                          Mel Wood Level 1

                          Ok, so I think I've fixed it just now! Testing for the past 30 mins seems to show now funny things happening anyway!

                           

                          So the problem was I was closing my for loop in the wrong place. All my if statements were sitting inside the for loop! What a dime bar thing to do!

                           

                          So the code now 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 < 100)&&(totalCCM > 0)){
                                  var showPromo = true;
                                  var hidePromo = true;
                                  MoForig.value = 0;
                                  MoForig2.value = 0;
                              }
                              else if(totalCCM == 0){
                                  var showPromo = false;
                                  var hidePromo = false;
                                  MoFoffer.value = 0;
                                  MoFoffer2.value = 0;
                              }

                           


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

                           


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

                           

                           

                          I'll double check over the next few days to make sure it's working properly and I will let you guys know so I can finally close this thread!

                          • 11. Re: how do I get my offer pricing to work?
                            Mel Wood Level 1

                            All FIXED!

                             

                            Thanks for everyone's help on this. It's very much appreciated that people are willing to help out!