• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

need help with loop

Explorer ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Hi, I have 4 radio buttons named "group1" and 4 text fields named text1-text4, I need help to loop through widgets of those buttons and if it's not off to input text in corresponding text field. I tried standard loop code but I can't get it to work with widgets.

TOPICS
JavaScript

Views

713

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 08, 2021 Apr 08, 2021

Yes,  you can do that. Here is a sample loop that prints out the checked state for each widget in a radio button group:

 

var f = this.getField("Group1");
var n = f.exportValues.length;
for (var i=0; i<n; i++) {
    console.println(this.getField("Group1." + i).isBoxChecked());
}

Information about the difference between fields and widgets is in the API documentation: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2FField.htm

 

Votes

Translate

Translate
Community Expert ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

There is no need to loop through the radio buttons: A radio button group returns the one selected item. Let's say you have one text field, and you want to display the value of the radio button group, you would add the following as the calculation script for the text field:

 

var v = this.getField("Group1").value;
event.value = v;

 

Does that help you with your problem? 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Thanks for your response, sorry I guess I didn't describe my problem correctly, so like I said I have 4 rb named "group1" and 4 text fields named text1-text4, (this part I didn't describe correctly) if lets say 3rd rb is checked I need text3 value to show in another text field named "text"  if 2nd rb is checked text2 populate "text"...etc I know how to do it with checkboxes but I have problem because don't know how to use widgets in a loop.

So 1st rb should be  linked to text1, 2nd rb to text2...etc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

You may want to invest some time into learning some basic JavaScript. The remaining part is pretty much just regular JavaScript. 

When you add the following script as the custom calculation script of "text", it should work (you may need to adjust the field names that are used):

 

var v = this.getField("Group1").value;
var retVal = "";
if (v == "Choice1") {
    retVal = this.getField("Text1").value;
}
else if (v == "Choice2") {
    retVal = this.getField("Text2").value;
}
else if (v == "Choice3") {
    retVal = this.getField("Text3").value;
}
else if (v == "Choice4") {
    retVal = this.getField("Text4").value;
}
else {
    retVal = "";
}
event.value = retVal;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

I appreciate your help, but my question was how to loop through radio buttons widgets.

I know some basic javascript and I did research online but all I could find was to loop through radio buttons groups  and not widgets so I was hoping someone could show me the way to do it if there is any at all.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Let's take a step back: Why would you want to loop through the widgets? There is no need to do that for what you listed as your requirements. You get the selected value from the "value" property of the radio button group. If no selection is made, it reports "Off", if there is a selection, it will report what was set as "Radio Button Choice" on the  "Options" tab. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

I would just like to know if it's possible or not.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

LATEST

Yes,  you can do that. Here is a sample loop that prints out the checked state for each widget in a radio button group:

 

var f = this.getField("Group1");
var n = f.exportValues.length;
for (var i=0; i<n; i++) {
    console.println(this.getField("Group1." + i).isBoxChecked());
}

Information about the difference between fields and widgets is in the API documentation: https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJ...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines