10 Replies Latest reply on Sep 3, 2015 11:53 AM by jay45807004

    Radio Buttons - assigning positive or negative values to associated form fields.

    juliecp

      Hi, how do I set two radio buttons (one is titled Increase, the other is titled Decrease), so that depending on which button they select, the $ amount that they enter in the associated form field is automatically either positive or negative? Thanks.

       

       

       

        • 1. Re: Radio Buttons - assigning positive or negative values to associated form fields.
          juliecp Level 1

          Or the reverse, how would I set the associated form field so that it is has a positive or negative value depending on which radio button is selected?

          • 2. Re: Radio Buttons - assigning positive or negative values to associated form fields.
            gkaiseril MVP & Adobe Community Professional

            Are you sure you want to use radio buttons?

             

            Do you know how radio buttons work?

             

            How is your calculation script structured. If you check the value of the radio button within the calculation body, each time the script is executed by updating any field your amount will be decreased by the value of radio button.

             

            Have you considered using a button field?

            • 3. Re: Radio Buttons - assigning positive or negative values to associated form fields.
              jay45807004

              I've never used javascript or adobe pro before and am going to take an online tutorial for both, but I could really use some help now for a change order form at work.   Basically part of the form looks like:

               

              o Increase       o Decrease              $____________________

               

              If users select the decrease radio button and always enter a negative sign before their dollar digits, there wouldn't be a problem, but half the time they forget, and the total ends up being incorrect, so that's why I need to make the  $ field automatically negative if the decrease button is selected.  The Increase button is named under the General tab as Group 1 and under the Options tab as Radio Button Choice: Choice1

              The Decrease button is named under the General tab as Group 1 and under the Options tab as Radio Button Choice: Choice2

              I think I have to identify in Javascript the Decrease button, them maybe do some sort of boolean If statement, but I don't know how to phrase any of this. Please help!

              • 4. Re: Radio Buttons - assigning positive or negative values to associated form fields.
                jay45807004 Level 1

                I've figured out how to hide or show the negative parentheses around the $_______________ based on which radio button is clicked, but i still haven't figured out the correct code to make the field value automatically negative if the Decrease button is selected.  My best guess is javascript under the Mouse Up event on the Decrease radio button, but is still isn't working:

                 

                if (event.target.value=="Choice2") {this.getField("ChangeOrder") = -1 * this.getField("ChangeOrder").value}

                 

                Any suggestions?  Also, what if a user actually enters a negative sign before entering the $ amount.  Would that make the figure positive, and is there anyway to make it stay negative? Thanks.

                • 5. Re: Radio Buttons - assigning positive or negative values to associated form fields.
                  jay45807004 Level 1

                  I've tried to find out about the difference between a button field and radio buttons without success.  This is driving me crazy, I've also tried several javascript variations in the ChangeOrder field custom calculation script, but it's still not working, this is my latest attempt:

                  var v1 = this.getField("Group1").value;

                  var neg = ChangeOrder * -1;

                  if (v1 == "Choice2") {event.value = neg;}

                   

                  Could anyone tell me / point me in the right direction?  Part of the form is:

                   

                  Change Order.jpg

                  • 6. Re: Radio Buttons - assigning positive or negative values to associated form fields.
                    try67 MVP & Adobe Community Professional

                    To access the value of a field you must use the getField method and the value property, like you did in the first line of your code.

                    • 7. Re: Radio Buttons - assigning positive or negative values to associated form fields.
                      jay45807004 Level 1

                      I tried this.getField but still wasn't able to write the correct javascript with radio-buttons to make it work, so I've switched to checkboxes (I've created about 50 fillable forms for work that we're going to upload to a new website under construction, so I've learned a little javascript, but obviously not enough yet, I've only had trouble with a few forms, and this is the second to last one that is giving me heartburn.  I have a meeting with my boss about the forms, I'd really appreciate any help).  Just to recap, I'm trying to make the form so that users have to select either increase or decrease, and whatever number they enter in the ChangeOrder field is correspondingly positive or negative.

                       

                      o Increase   o Decrease          $___ChangeOrder__________

                       

                      Both checkboxes are named CheckBox1.  The checkbox in front of Increase has an export value of: Yes

                      The checkbox in front of Decrease has an export value of: Decrease

                       

                      When I try the following different scripts in the ChangeOrder custom calculation script, I get the same result:  the number a user enters in the ChangeOrder field is automatically negative, then whichever checkbox is clicked on first (either for Increase or Decrease) will change the number to positive, then the other checkbox will change it back to negative.  Most of the time these ChangeOrder numbers will be positive, so I need the number the user enters to first show up as positive, then the checkbox for Increase can only make the ChangeOrder number positive, and the checkbox for Decrease can only make the Change Order number negative.  Please help!

                       

                      var v1 = this.getField("CheckBox1").value;

                      var v2 = this.getField("ChangeOrder").value;

                      if (v1 = "Yes") {event.value = this.getField("ChangeOrder").value}

                      if (v1 = "Decrease") {event.value = v2 * -1}

                      if (v2 ==0) {event.value = ""}

                       

                      //the second script with same result:

                      var v1 = this.getField("CheckBox1");

                      var v2 = this.getField("ChangeOrder").value;

                      var neg = v2 * -1;

                      if (v1 = "Yes") {event.value = v2}

                      if (v1 = "Decrease") {event.value = neg}

                      if (v2 ==0) {event.value = ""}

                       

                      //another script where the ChangeOrder number shows up positive as it is entered and stays positive not matter which checkbox is selected:

                      • 8. Re: Radio Buttons - assigning positive or negative values to associated form fields.
                        jay45807004 Level 1

                        //another script where the ChangeOrder number shows up positive as it is entered and stays positive no matter which checkbox is selected:

                        var v1 = this.getField("CheckBox1").value;

                        var v2 = this.getField("ChangeOrder").value;

                        if (v1 = "Yes") {event.value = this.getField("ChangeOrder").value} else if (v1 = "Decrease") {event.value = v2 * -1}

                        if (v2 ==0) {event.value = ""}

                        • 9. Re: Radio Buttons - assigning positive or negative values to associated form fields.
                          try67 MVP & Adobe Community Professional

                          The comparison operator is "==", not "=".

                          • 10. Re: Radio Buttons - assigning positive or negative values to associated form fields.
                            jay45807004 Level 1

                            Thank you!!!!!!  I finally got this part to work with:

                             

                            var v1 = this.getField("CheckBox1").value;

                            var v2 = this.getField("ChangeOrder").value;

                            if (v1 == "Yes" && v2 <0) {event.value = v2 * -1}

                            if (v1 == "Yes" && v2 >0) {event.value = v2}

                            if (v1 == "Decrease" && v2 >0) {event.value = v2 * -1}

                            if (v1 == "Decrease" && v2 <0) {event.value = v2}

                            if (v2 ==0) {event.value = ""}