Skip to main content
Participant
April 6, 2020
Answered

Changing Radio Button value /JavaScript/

  • April 6, 2020
  • 1 reply
  • 3971 views

Hello there,
Is there a way to change the value of a Radio button with some kind of  JavaScript "If function"?

The dropdown box /pixelamount/ has 3 options: 1024/2048/4096 
To every option there are 3 radio buttons /Group1/: A, B, C

My problem is that every option should have a radio button with different value e.g.:
1024: A = 10
2048: A= 20
4096: A= 30
and i have no clue how to achieve it. 

Thanks in advance for any tips!

This topic has been closed for replies.
Correct answer Thom Parker

Yes, it requires a script.  The issue is about organizing data/code. Each dropdown selection changes the values used by the radio buttons, so it is slightly more complicated than simply adding up values. It is better to change the calculation script.

 

Here's an example, This is not the complete or correct script. It just shows how it need to be setup. Notice that the intial calculation is not complete (no field name) and not all conditions are shown in the switch statment.

 

// First do the regular calculation
event.vaue = this.getField("...") + this.getField("...");

// Now add dependent value from radio button
var cPixValue = this.getField("pixelamount").value;
var cRadValue = this.getFiel("Group1").value;
switch(cPicValue)
{
    case  "1024":
      switch(cRadValue)
      {
          case "A":
             event.value += 10;
             break;
          case "B":
             event.value += 20;
             break;
             
      }
      break;
    case "2048":
      break;
    case "4096":
      break;
} 

 

1 reply

Thom Parker
Community Expert
Community Expert
April 6, 2020

How are these radio button values used?  If it's a calculation, then maybe it would be better to change the calculation, than to modify the radio button exports. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
April 6, 2020

Each radio button has a value /price of a license/ which is added to the value of the dropdown button /price of hardware/ in the text field /Total/. What i want to achieve is that the value of radio button will be linked to the selected option of dropdown button, because the price for license changes depending on the version of the hardware.
So i'm not sure if it would be possible without some use of script.
Sorry for the butchered english, hope it makes some sense.