To select a radio button add a number in a text field

Community Beginner ,
Jun 12, 2019

Copy link to clipboard

Copied

I have several groups of radio buttons. If I select the second button of the group (value 2), this selection add “1” to the content of a text field. So, for example, if I select the second value of four radio button groups, the text field shows “4”. How can I do this? Thank you so much

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK. You can use this code as the custom calculation script of the field where you want to display the result, then:

var total = 0;

for (var i=1; i<=8; i++) {

    var f = this.getField("ev_"+i);

    if (f.valueAsString=="2") total++;

}

event.value = total;

TOPICS
Acrobat SDK and JavaScript

Views

88

Likes

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

To select a radio button add a number in a text field

Community Beginner ,
Jun 12, 2019

Copy link to clipboard

Copied

I have several groups of radio buttons. If I select the second button of the group (value 2), this selection add “1” to the content of a text field. So, for example, if I select the second value of four radio button groups, the text field shows “4”. How can I do this? Thank you so much

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

OK. You can use this code as the custom calculation script of the field where you want to display the result, then:

var total = 0;

for (var i=1; i<=8; i++) {

    var f = this.getField("ev_"+i);

    if (f.valueAsString=="2") total++;

}

event.value = total;

TOPICS
Acrobat SDK and JavaScript

Views

89

Likes

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
Jun 12, 2019 0
Most Valuable Participant ,
Jun 12, 2019

Copy link to clipboard

Copied

So each time you select that button it should increment the value of the text field by 1?

Likes

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
Reply
Loading...
Jun 12, 2019 0
Community Beginner ,
Jun 12, 2019

Copy link to clipboard

Copied

No, simply if there are, for example, 8 groups of radiobutton and 3 groups are selected on the second value, the text field show “3”.

Likes

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
Reply
Loading...
Jun 12, 2019 0
Most Valuable Participant ,
Jun 12, 2019

Copy link to clipboard

Copied

Ah, so you want to count how many of the second values are selected? What are the names of the groups, and what is the export value of the second fields in them?

Likes

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
Reply
Loading...
Jun 12, 2019 0
Community Beginner ,
Jun 12, 2019

Copy link to clipboard

Copied

Right. The radiobuttons groups are “ev_1” ”ev_2” “ev_3” “ev_4”. The export value of the second field is always “2”.

Likes

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
Reply
Loading...
Jun 12, 2019 0
Most Valuable Participant ,
Jun 12, 2019

Copy link to clipboard

Copied

OK. You can use this code as the custom calculation script of the field where you want to display the result, then:

var total = 0;

for (var i=1; i<=8; i++) {

    var f = this.getField("ev_"+i);

    if (f.valueAsString=="2") total++;

}

event.value = total;

Likes

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
Reply
Loading...
Jun 12, 2019 0
Community Beginner ,
Jun 13, 2019

Copy link to clipboard

Copied

Right. Thank you so much

Likes

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
Reply
Loading...
Jun 13, 2019 0