Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

calculation script based on value of a radio button

Avatar

Level 3

I am wondering if anyone can give me some help. I am trying to make a calculation script that I can insert into a number field that will only calculate when a radio button is checked. I am trying to do an estimate sheet that when certain check boxes or radio buttons are selected (Such as moving furniture, pulling up old flooring) it will calculate an additional charge based on that selection. Any help would be much appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Paul is right, it is probably something small which is causing the script to fall over. Make sure that the objects you are referring to in your script are correct (right name and full reference if in different subforms).

Also there is a check syntax button at the top of the script editor. If you click this it might identify the problem.

In case it might help, here is a sample: https://acrobat.com/#d=bUfCkHbTaU0*GD6Y7pv41w

Good luck,

Niall

View solution in original post

6 Replies

Avatar

Level 10

Hi,

There are a couple of approaches.

One would be to put the script in the radio buttons that when clicked would do the calculate and set the value of the numeric field.

Another would be to have the script in the calculate event of the numeric field looking back at the value of the radio button. Taking this approach the script in the numeric field calculate event would look like this:

if (radioButton.rawValue == 1) // radio button bound to 1 is on/yes

{

     this.rawValue = ; // your calculation goes here

}

else

{

     this.rawValue = null;

}

This is testing the value of the radio button and then taking appropriate calculations.

Hope that helps,

Niall

Avatar

Level 3

Okay thanks for that. But are there stipulations to that code working? Like being a dynamic form? I am not sure what I am doing wrong. The code does not work in what I am doing for some reason. And just to make sure it was not the code, I started a new form and did some basic fields (radioButtons and Numeric fields) The code worked fine there. I have looked it all over in the form I am trying to put this code into for hours now and nothing comes to me. The "0" does show up in the numeric field when its tested but nothing happens when the radio button is selected. I know I am doing something wrong, just don't know what it is. Any idea's?

Avatar

Level 10

You probably have a scripting error and the code is not running. If you hit Ctrl-J in Acrobat while the form is running you will expose the Javascript console ....any errors will appear there.

Paul

Avatar

Correct answer by
Level 10

Hi,

Paul is right, it is probably something small which is causing the script to fall over. Make sure that the objects you are referring to in your script are correct (right name and full reference if in different subforms).

Also there is a check syntax button at the top of the script editor. If you click this it might identify the problem.

In case it might help, here is a sample: https://acrobat.com/#d=bUfCkHbTaU0*GD6Y7pv41w

Good luck,

Niall

Avatar

Level 4

I was looking for a solution for this issue but wasn't able to figure it out from the above post.  Basically, I want to write a script that puts a text string into the numeric field if the radio button is not checked, and to do a calculation if the button is checked.

I'm having trouble figuring out how to call out the radio buttons in the script (The "binding" tab only seems to bind the whole list of radio buttons, and not just the single one.

The sample link above downloads the PDF, and the radio buttons and menu work fine from the end user side, but when I open it in  LiveCycle Designer, I don't see the script anywhere.

Avatar

Level 10

Hi,

In  the example the script is in the click event of the radio button group (gender). It basically tests the value of the group, eg which radio button was clicked and takes appropriate action. I have put an updated version on Acrobat.com, which shows the script: https://acrobat.com/#d=bUfCkHbTaU0*GD6Y7pv41w

It is tricky to override a calculation event, so this sample (https://acrobat.com/#d=4-qeMnSXqmRNBf0xyY6RUg) has the script in the exit events of the inputs. You can't script a numericField to have a text string rawValue; however it can have a text string pattern.

Hope this helps,

Niall