1 Reply Latest reply on Jun 23, 2015 11:51 AM by gkaiseril

    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;

          }