Copy link to clipboard
Copied
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!
1 Correct answer
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 reg
...
Copy link to clipboard
Copied
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.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you very much, this helped me a lot!
Is there a way to sum only the numbers of the values? The results i'm getting are e.g: 300A30 instead of 330.
I think it's because of the A value of the radio button.
Copy link to clipboard
Copied
The problem is that JS is interpreting event.value as a string. It looks like this is happening because event.value is being set to string, i.e. "300A". Where is the "A" coming from? Looks like one of your inputs is not a number.
Another stuctural change that will help, is to use a separate varaible for the calculation result that is explicitly cast as a number. Then set event.value to this number at the end.
// This code just shows ordering of operations
// Calculation needs to be numberic.
var nSum = ... regular calculation (numbers only) ...
nSum = .. radio button swtich statment ...
event.value = nSum;
Use the Acrobat JavaScript Reference early and often

