2 Replies Latest reply on Sep 23, 2014 8:31 AM by tjq09

    Check Boxes combined with IF functions

    tjq09

      I have a section of a form that requires you to check "RateComparison" or "MultiLocation". Depending on which box is checked, the "Lodging" line will be filled.

       

      Here is the written version of my goal:

       

      If "RateComparision" is checked, then "Lodging" is equal to the lowest value of "TripTotal1", "TripTotal2", and "TripTotal3".

      If "MultiLocation" is checked, then the "Lodging" is equal to "GrandTotal".

       

       

      And... here is the nightmare of a code I've created. *Note: RateComparison and MultiLocation are both under CheckBox "Group1"

       

      var a = this.getField("TripTotal1").value;

      var b = this.getField("TripTotal2").value;

      var c = this.getField("TripTotal3").value;

      var d = this.getField("CheckOne").value;

      var e = Math.min(a, b, c);

      if (d === "On") {this.getField("TotalBacktoTravelRequest").value = e; }

      if (d === "Off") {this.getField("TotalBacktoTravelRequest").value = this.getField("TotalTrips").value; }

       

       

      Thanks for any help!

        • 1. Re: Check Boxes combined with IF functions
          George_Johnson MVP & Adobe Community Professional

          A few questions:

           

          Is is possible that neither RateComparison or MultiLocation is selected? If so, what should happen? Are you using radio buttons or check boxes for these? What are the export values ("Button Value" or "Radio Button Choice" for radio buttons)?

           

          You say you want to set the Lodging field to a value, depending on which is selected, but your code seems to be setting the value of the TotalBacktoTravelRequest field. Can you clarify? Also, where did you place that code?

          • 2. Re: Check Boxes combined with IF functions
            tjq09 Level 1

            I actually ended up finding another example. Here, RateComparison has been changed to Choice1 and MultiLocation is Choice2.

             

            var a = this.getField("TripTotal1").value;

            var b = this.getField("TripTotal2").value;

            var c = this.getField("TripTotal3").value;

            var e = Math.min(a, b, c);

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

            if (rb === "Choice1") {this.getField("Lodging").value = e; }

            if (rb === "Choice2") {this.getField("Lodging").value = this.getField("TotalTrips").value; }

            if (this.getField("TotalTrips").value === 0) {this.getField("Lodging").value = 0; }

             

            In response to your questions, I did have one selected.

            If RateComparison (Choice1) was selected, "Lodging" should reflect the lowest total of the three TripTotal choices. If MultiLocation (Choice2) was selected, "Lodging" should reflect the grand total of the three TripTotal choices (TotalTrips).

            I am using radio buttons.

            "TotalBacktoTravelRequest" was the original title for "Lodging", so that explains part of why my original formula wouldn't work.

             

            I added the extra line at the bottom to make sure "Lodging" reflected "0" if there were no totals, though I'm not sure if it was completely necessary!

             

            Is this the most accurate way to do this? If there is an easier code, I'd love to hear it!

             

            Thanks!