These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Calculation based on choice with radio button and multi select

marmoren
Registered: Feb 12 2009
Posts: 4
Answered

OK, I have tried all possible avenues to do this.
Simply put, I am needing to change the value of a text field, based on the radio button selection of the user.

They can select to pay the total amount (which is already populated in another field) or they can choose to be billed later, which makes that field be equal to zero. I am not a Javascript expert, but if I can get a bit of help, I will be able to finish this form.

Here's what I have:

var adpayment = this.getField("advertising_payment");//advertising_payment if the name of the radio button field

var selection = adpayment.value;

var totaladv = this.getField("total_from_page_10"); //this is the total payment

if
(selection.value == "invoicelater")
{event.value = 0}

else
{event.value = totaladv.value};

I have another case where they select the radio button and also from a pull down menu so the case would be an "AND" statement. However, since my other example doesn't work, I know I am not doing it correctly.

Your help is appreciated.

My Product Information:
Acrobat Pro 9.0, Windows
maxwyss
Registered: Jul 25 2006
Posts: 255
The selection variable is already a field object value. Therefore, you won't get any result by using its value.

The evaluation should read

if (selection == "invoicelater")

and that should work out (if one of the return values in adpayment is actually "invoicelater".

Hope this can help.

Max.
marmoren
Registered: Feb 12 2009
Posts: 4
Hi Max,

Thanks for your great help. This works. Now, there is a new layer of complexity, in which I need to check for two conditions to be true for something to happen. Applying the same concept, I wrote this code snippet, and it is not giving me the results that I am looking for. Basically, if two radio buttons are clicked, the price for the text box in question should change.



var adselection = this.getField("fullpageradiogroup");
var adtypeselection = fullpageradiogroup.value;

var colorselect = this.getField("black_white_or_color");
var colorselection = black_white_or_color.value;

if
(adtypeselection == "fullpage" && colorselection == "bw")
{event.value = 750};


if
(adtypeselection == "fullpage" && colorselection == "four_color")
{event.value = 950};


if
(adtypeselection == "twothirds" && colorselection == "bw")
{event.value = 625};


if
(adtypeselection == "twothirds" && colorselection == "four_color")
{event.value = 825};

//this continues on for a group of four values.

Thanks for your help. I am very close!
maxwyss
Registered: Jul 25 2006
Posts: 255
OK, with multiple conditions, it is worthwile you sit down and use good ol' paper and pencil to write down the logic (that's what I do too). In order to get the working logic, you have to "simulate" all possible conditions. Sometimes, it is also better to evaluate for the non-presence of an option.

In this case, assuming that we have two options each, I would first evaluate one condition (typeselection, for example), and then in a second if ... else construct the second option, which you may have to repeat...

Max.