8 Replies Latest reply on Apr 8, 2015 2:17 PM by hasand59089870

    Alter the value of one field when the value of another field changes.

    ericl42424768 Level 1

      I have a standard order form that has a number of fields where the quantity (number )is typed in  They are labelled qty1, qty2  and so on.

       

      Some of the items on the order form attract an additional fixed one off charge which is shown in a separate field call it addcharge.

       

      If qty1  has a number entered it attracts an added charge and the addcharge field alters value from nil to say 1

      If qty2  has a numbered entered no additional charge applies

      If qty3  has a numbered entered no additional charge applies

      If qty4  has a number entered it attracts an added charge and the addcharge field alters value from nil to say 1 or if the previous qty1 has already altered the addcharge field to 1 it stays at 1.

      If qty5  has a number entered it attracts an added charge and the addcharge field alters value from nil to say 1 or if the previous qty1 and qty4 has already altered the addcharge field to 1 it stays at 1


      It seems to me that some "if else" activation javascript is needed  along the lines of "if field qty1 is greater than 0 the field addcharge is 1" and I assume the script should be placed in every qty field that attracts addcharge.


      Can any one help with the script please.


      Thanks Eric

        • 1. Re: Alter the value of one field when the value of another field changes.
          hasand59089870 Level 2

          if i unsterstand right. If one of the fields (qty1, qty4, qty5) has a quantity more than 0 than addcharge become 1.

          If a unsterstand right, this should be work.

           

          this.getField("qty1").setAction("OnBlur", 'xcharge()');

          this.getField("qty4").setAction("OnBlur", 'xcharge()');

          this.getField("qty5").setAction("OnBlur", 'xcharge()');

           

          function xcharge() {

            if (this.getField("qty1").value > 0 || this.getField("qty4").value > 0 || this.getField("qty5").value > 0){

               this.getField("addcharge").value = 1

            } else {

               this.getField("addcharge").value = 0

            }

          }

          • 2. Re: Alter the value of one field when the value of another field changes.
            ericl42424768 Level 1

            Sorry it has taken a little time to say thanks for this, I have been out of action for a short while.

             

            I am still having problems, for simplicity I have listed all the addcharge items together at the beginning of the  form,  so that they are Qty1 to  Qty7. and the addcharge field is 15.00. I have amended the script as follows

             

            this.getField("qty1").setAction("OnBlur", 'xcharge()');

            this.getField("qty2").setAction("OnBlur", 'xcharge()');

            this.getField("qty3").setAction("OnBlur", 'xcharge()');

            this.getField("qty4").setAction("OnBlur", 'xcharge()');

            this.getField("qty5").setAction("OnBlur", 'xcharge()');

            this.getField("qty6").setAction("OnBlur", 'xcharge()');

            this.getField("qty7").setAction("OnBlur", 'xcharge()');

             

            function xcharge() {

              if (this.getField("qty1").value > 0 || this.getField("qty2").value > 0 || this.getField("qty3").value > 0 || this.getField("qty4").value > 0 ||this.getField("qty5").value > 0 ||this.getField("qty6").value > 0 ||this.getField("qty7").value > 0){

                 this.getField("addcharge").value = 15

              } else {

                 this.getField("addcharge").value = 0

              }

            }

             

            When the pdf is filled in and say a 1 is entered into qty1  the addcharge field remains at nil,  if say a 2 is is entered in qty4 the add charge then appears, no matter which qty field is chosen for entry first it always takes a second qty field to have an entry before the add charge appears. This is OK if the customer wants 2 different items, but if only one item is chosen no add charge appears.   Any suggestions please.

            • 3. Re: Alter the value of one field when the value of another field changes.
              hasand59089870 Level 2

              if it happens only by the field "qty1" i would control the name of this field. Is the fieldname really qty1.

              • 4. Re: Alter the value of one field when the value of another field changes.
                hasand59089870 Level 2

                the following code, i have changed the setaction Trigger and set it to the addcharge calculate. I think it's better. Please delete the old one or rewrite as new.

                The effect should be same. Firs you must control the names of the fields.

                 

                this.getField("addcharge").setAction("Calculate", 'xcharge()');

                 

                function xcharge() {
                    if (this.getField("qty1").value > 0 || this.getField("qty2").value > 0 || this.getField("qty3").value > 0 || this.getField("qty4").value > 0 ||
                        this.getField("qty5").value > 0 || this.getField("qty6").value > 0 || this.getField("qty7").value > 0)
                    {
                        event.value = 15
                    } else {
                        event.value = 0
                    }
                }

                • 5. Re: Alter the value of one field when the value of another field changes.
                  ericl42424768 Level 1

                  Thanks again

                   

                  I applied the script in full to each "qty1" to "qty7" field.in the "actions" run a javascript boxes,it has made no difference, it still needs 2 "qty" fields to be filled for the "addcharge" to show.

                   

                  Another problem is now occurring.  If I delete all entries from the "qty" fields the sum of £15.00 disappears from the "addcharge" field as would be expected,  but now a "subtotal" field retains the £15.00, also the VAT charge is retained and the sum of both is retained in the totals field.  This did not happen before.  By making an entry into any "qty" field   the retained figures disappear  from the "subtotal"," vat" and "total" fields, and is replaced by the values of the item chosen, it then takes a second entry to get the "addcharge" to show up. 

                   

                  I have broken down the script so that each "qty" field has its own script for that field, but in use the form behaves exactly as above.

                   

                  Forgive my ignorance but what do you mean by controlling the names of the fields you seem to disapprove of "qty1" I have used the same names on other order forms without problems.

                   

                  I also notice in your original script you refer to "on blur"  I have set on blur in the run a script box, but it appears to make no difference when a click is made and a number is entered in a "qty" field, it still takes a 2nd click anywhere outside the field to see the calculated value?

                  • 6. Re: Alter the value of one field when the value of another field changes.
                    hasand59089870 Level 2

                    i've tested both codes. It works without problems. Can you make a new test form with these seven fields and the addcharge field. for testing. Maybe you another codes test or integratet which are in conflict with this. Which enviorement do you have.

                    • 7. Re: Alter the value of one field when the value of another field changes.
                      ericl42424768 Level 1

                      I have run a test form from a blank and as you said all works OK, To find or more precisely stop any script that may be causing a conflict, I deleted script that formatted numbers, and hiding zeros, setting date formats etc and now the calculations and addcharge work perfectly. Thank you for being so patient with me.  I now need to get a few of the features back and will use the inbuilt tools to do this where possible and check for any conflicts as I proceed. I have checked back with the original owners of the form and also in the properties dialogue of the form and it appears it was originally from an alternative PDF writer no longer in the owners possession.

                      Thanks again.