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

Help with JavaScript....

Avatar

Level 4

I have a form that has several groups named "transType", within these groups are a text field and a group of 3 radio buttons. Each radio button group has the values of Yes, No and Resolved. I have one radio button group at the top that, when clicked, the corresponding buttons on the page are also selected, e.g. I click "No" on the top group, and all the "No" fields below are selected. I am using the action builder to make this happen, but it seems tedious and I will have to do it for each value. Below is the script as it stands now:

form1.#subform[0].transType[0].markAll::change - (JavaScript, client)

     if (this.rawValue == "1") {

       this.resolveNode("transType[1].exeError").rawValue = "No";

       this.resolveNode("transType[2].newEnrol").rawValue = "No";

       this.resolveNode("transType[3].enrolReq").rawValue = "No";

       this.resolveNode("transType[4].immPinChange").rawValue = "No";

       this.resolveNode("transType[5].pinChange").rawValue = "No";

       this.resolveNode("transType[6].loanProc").rawValue = "No";

       this.resolveNode("transType[7].contribChange").rawValue = "No";

       this.resolveNode("transType[8].allocChange").rawValue = "No";

       this.resolveNode("transType[9].allocChange403b").rawValue = "No";

       this.resolveNode("transType[10].transfTrans").rawValue = "No";

       this.resolveNode("transType[11].confEndBal").rawValue = "No";

       this.resolveNode("transType[12].confTarAlloc").rawValue = "No";

       this.resolveNode("transType[13].loanReq").rawValue = "No";

       this.resolveNode("transType[14].withdrawReq").rawValue = "No";

     }

Is there a easier script I could write? Maybe an array? I'm a bit of a n00b in JavaScript, but I can limp my way around. TIA!!!

1 Reply

Avatar

Level 10

Hi

You could have a JavaScript function that takes a RadioButton group and a on value and sets which ever radio button that has that on value on, so;

function setOn(group, onValue)

{

    var radioButtons = group.resolveNodes('#field[*]');

    for (var i=0; i<radioButtons.length; i++) // Find the radio button with the "on" value of onValue

    {

        var radioButton = radioButtons.item(i);

        if (radioButton.items.nodes.item(0).value === onValue)

        {

            radioButton.value.text.value = onValue; // Set the radio button on

        }

    }

}

This assumes that the "Specify Items Values" on the binding tab is not set.  If it is then the "No", "Yes", "Resolved" radio buttons will probably have numeric values ... 1,2,3

So you could then call this in the buttons, like this one for the "No" button

var transTypes = xfa.resolveNodes("transType[*]");

for (var i = 0; i < transTypes.length; i++)

{

    var transType = transTypes.item(i);

    Script.setOn(transType, "No")  

}

This example might make more sense, https://files.acrobat.com/preview/6e5fbf69-e1e1-4514-982a-103eedda9c29

Good luck

Bruce