5 Replies Latest reply on Apr 11, 2014 3:25 AM by try67

    Automatically populating a field based on a selection in another field

    JohnRobinson62

      Hi

       

      I've hit a brick wall with this problem!

       

      I have a two page form that I am developing to assist with referring to a particular service. The first page is easy, just checkboxes, radio buttons and text fields.

       

      The second page, however, is a little more complicated. Of course it is, that's why I'm here!

       

      The second page consists of a table which has eight domains, each with three or four criteria. These criteria have a score of 0, 1, 2 or 3 and only one can be selected. These score are then totalled to give a score that will guide the level of service required.

       

      With me so far?

       

      My question is this: Can the scores field be automatically populated (with the score) depending on the selection and then automatically totalled at the end? Is it possible then to highlight the level of service suggested based upon the total score?

       

      Or can I have a total score based on selecting the scores themselves? The form I have so far simply has all the information in view and uses radio buttons to manual select the score and manually input a total at the end.

       

      I hope this makes sense what I'm asking!!!

       

      Kind regards

      John Robinson

        • 1. Re: Automatically populating a field based on a selection in another field
          try67 MVP & Adobe Community Professional

          So have you tried simply using the built-in Calculation option of a sum, and selecting all of your fields from the list? Maybe I'm missing something here, but it just sounds like you want to total a bunch of fields, which is easily done.


          However, I think that you made a mistake in choosing "0" as one of the possible values. When that option is selected, the result will be the same as if nothing is selected in the category, since adding zero and adding nothing to a total has the same effect...

          • 2. Re: Automatically populating a field based on a selection in another field
            JohnRobinson62 Level 1

            Thanks Gilad

             

            I obviously hadn't made myself clear in my ramblings!

             

            The "0"in form is important for reasons that may be clear if I could show the form itself (or a mockup).

             

            The main query is about populating fields with a particular score based on a selection, then automatically totalled at the end. I understand that a "0" will be the same as an empty box, but it does need to be there.

             

            Let me see if I can clarify my need:

             

            • The form has 8 Domains, each of has three or four criteria.
            • The user can choose only one of these criteria and a score of 0, 1, 2 or 3 is given based on the selection.
            • When the user has completed all 8 Domains, the scores are added together and the total then suggests the level of service required.

             

            Currently, the form consists of a table with checkboxes overlaying the scores and the user adds the scores together at the end before referring to the service. I just want to make it easier for the user by automating it. Hence why the "0" is important.

             

            Does this make more sense?

             

            John

            • 3. Re: Automatically populating a field based on a selection in another field
              try67 MVP & Adobe Community Professional

              So you want to calculate a total, but only if all "domains" are filled-in?

               

               

              On Fri, Apr 11, 2014 at 11:51 AM, JohnRobinson62

              • 4. Re: Automatically populating a field based on a selection in another field
                JohnRobinson62 Level 1

                Yep, that's correct.

                 

                I was thinking also it may be better to have drop-down lists for each of the domains rather than a straight table. What do you think?

                • 5. Re: Automatically populating a field based on a selection in another field
                  try67 MVP & Adobe Community Professional

                  Drop-downs are good, yes, but then you can't have two values with the same export value. You can have one with a blank export value and one with "0", but not two zeros.

                   

                  Anyway, this can be done with a custom calculation script. Let's say the names of your fields are Domain1 to Domain8. You can use this code as the custom calculation script of the Total field:

                   

                  var counter = 0;

                  var total = 0;

                  for (var i=1; i<=8; i++) {

                      var f = this.getField("Domain"+i);

                      if (f.value==f.defaultValue) continue;

                      counter++;

                      total += Number(f.value);

                  }

                   

                  if (counter==8) {

                      event.value = total;

                  } else event.value = "";