1

I am trying to have the "values" of radio buttons change, dependent on the selection of other radio buttons. (This is for a PDF Form in Adobe Pro (not designer)

The code which I have tried (inserted on the SingleTotal field) is as follows: however it is not calculating:

// Custom Calculate script
(function(){


//declare vars


var oFldSec1 = this.getField("A");
var oFldSec2 = this.getField("B");
var oFldSec3 = this.getField("C");
var oFldSel = this.getField("Options Single");
var oFldSub = this.getField("SingleTotal");

if(oFldSec1.checked) {

     switch(oFldSel.value)
   {
      case "boy":
        event.value = 30;
        break;
      case "girl":
        event.value = 35;
        break;
        default:
        event.value = 0;
        break;
   }
}
else if(oFldSec2.checked) {

switch(oFldSel.value)
   {
      case "boy":
        event.value = 40;
        break;
      case "girl":
        event.value = 45;
        break;
        default:
        event.value = 0;
        break;
   }
}

})

Any help will be greatly appreciated. Thank you :)

8
  • Shouldn't that be if(oFldSec1.checked) and if(oFldSec2.checked) Commented Nov 1, 2012 at 18:04
  • @Asad - thank you for your help. I have changed it as you have stated, unfortunately it is still not calculating? :-) Commented Nov 1, 2012 at 18:06
  • Where are you defining event? And why is your function unnamed? Commented Nov 1, 2012 at 18:07
  • I am very new to javascript, and unfortunately am unsure on how to answer your questions? Thank you so much for your reply Commented Nov 1, 2012 at 18:11
  • That's okay. Unfortunately I have some bad news for you. Radio buttons don't have values per se. They just have a checked option that is true or false. Commented Nov 1, 2012 at 18:13

2 Answers 2

1

From the docs, radiogroups and checkgroups do not use the value property to store their current state, so you're out of luck there.

Try:

(function() {

    //declare vars
    var oFldSub = getField("SingleTotal");
    var total = 0;

    var selectedPlan =  getField("PlanOptions").valueAsString;
    var selectedSingle = getField("OptionsSingle").valueAsString;

    if (selectedPlan == "A") {

        switch (selectedSingle) {
        case "boy":
            total = 30;
            break;
        case "girl":
            total = 35;
            break;
        default:
            total = 0;
            break;
        }
    }
    else if (selectedPlan == "B") {

        switch (selectedSingle) {
        case "boy":
            total = 40;
            break;
        case "girl":
            total = 45;
            break;
        default:
            total = 0;
            break;
        }
    }
    event.value = total;
})()
Sign up to request clarification or add additional context in comments.

Comments

0

If you are simply adding or multiplying, I would step back from VBA and try a "Value is the __ of the following fields".

For example give Field Plan A an export value of 0 and Plan B a value of 10, Boy a value of 30 and Girl a value of 35.

Then where ever the total is suppose to go, tell that field to calculate its value as the sum of PlanA, PlanB, Boy, Girl

If PlanA is selected and girl is selected, then the value will be 35.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.