2 Replies Latest reply on Mar 14, 2018 4:36 AM by AmirAnsari

    How to populate a text field when a radio button is chosen?

    leec89005453

      I am not a JavaScript programmer so I have no idea what to do.  I want a text field to be populated when a radio button is chosen.  Basically, it's when clients chose a package the price would show up on the price text field.  Any help would be appreciated. Thanks!

        • 1. Re: How to populate a text field when a radio button is chosen?
          gkaiseril MVP & Adobe Community Professional

          It is a simple matter of using a custom calculation script in the text field to set that field's value to the value of the radio button group unless the value for the group is "Off". This requires proper setup[ of the exclusionary radio button group. You need to create a group of radio buttons all with the exact same name. Then for each button field within the group, widget, you need to set the export value to a unique value, this could be the price if each price is unique. Now one need to write some a custom JavaScript calculation to use the value of the radio button group to set the event value of the text field to the price.

           

          I would use the switch statement using the value of the radio button group to make the selection. This will allow for multiple items to have the price.

           

          // set price based on the value of the radio buttons;

          switch(this.getField("RadioButtonField").value) {

          case "Off" :

          // no item selected;

          event.value = "";

          break;

          case "1" :

          // item one;

          event.value = 0.10;

          break;

          case "2" :

          case "3" :

          // item 2 and 3 have the same price;

          event.value = .20;

          break;

          default:

          // item with no price value;

          event.value ="";

          app.alert"Missing price for item with value of : " + this.getField("RadioButtonField").value, 1, 0);

          break;

          }

          • 2. Re: How to populate a text field when a radio button is chosen?
            AmirAnsari

            Hi gkaiseril, can I get some clarification:

             

            1. The code you have mentioned - does I insert it in the Script Editor after I selected the text field?

            2. You say each radio button have to have the same name? I don't understand. I have one group, it has four radio buttons with different names and values. By name, are you referring to the actual radio button label or another name?

             

            Cheers. Amir