Page 1 of 1

How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?

Posted: Wed Sep 22, 2021 1:13 pm
by bram147
Hey guys!

I'll get straight to the point. Basically I have a yes/no question and have put radio buttons near "Yes" and "No".

Now if the answer is "no", one should move on and read the document(nothing should happen). However, if the answer is "Yes", the radio button/check box at the end of the document should get checked automatically.

So, in my kind of ignorant beginner's view, at the first Radio Button's(the one near "Yes") Properties > Actions > On Focus, I should run a JavaScript code that basically says:

If Button near "Yes" is checked, then Button at the end should get checked.

I have very limited knowledge of JavaScript or how I could write this code. Any help?

Thanks in advance! :)

Re: How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?

Posted: Wed Sep 22, 2021 1:46 pm
by Tracker Supp-Stefan
Hello bram147,

Please take a look at the attached file:
test_checkbox.pdf
(8.4 KiB) Downloaded 44 times
There's a radio button group, and when you click the "no" option ( the code is on the "on Focus" event for that) - it validates if the checkbox on the same page is already checked and if not - it adds the check mark in it.

Now you can improve on that and add more validations - e.g. ensure that the correct value of the radio button group is actually clicked and selected, and you can also e.g. make it so that selecting other of the radio options unchecks this box.

Kind regards,
Stefan

p.s. Actually - here's another version of the file - where the first radio option now hides the check mark and the second adds it:
check_uncheck_checkbox.pdf
(8.42 KiB) Downloaded 35 times

Re: How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?

Posted: Wed Sep 22, 2021 2:31 pm
by bram147
Tracker Supp-Stefan wrote: Wed Sep 22, 2021 1:46 pm Hello bram147,

Please take a look at the attached file:
test_checkbox.pdf

There's a radio button group, and when you click the "no" option ( the code is on the "on Focus" event for that) - it validates if the checkbox on the same page is already checked and if not - it adds the check mark in it.

Now you can improve on that and add more validations - e.g. ensure that the correct value of the radio button group is actually clicked and selected, and you can also e.g. make it so that selecting other of the radio options unchecks this box.

Kind regards,
Stefan

p.s. Actually - here's another version of the file - where the first radio option now hides the check mark and the second adds it:
check_uncheck_checkbox.pdf
Thank you very much! That's very helpful!

How would I go about it if there weren't a checkbox at the end, but two radio buttons? How would the code change to call one button, not the whole field?

Re: How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?

Posted: Thu Sep 23, 2021 8:07 am
by Tracker Supp-Stefan
Hello bram147,

It is the state of the radio button group that controls the checkbox.
Or is it that you want one radio button group to control another radio button group?

Please take a look here for the full JS API documentation:
https://opensource.adobe.com/dc-acrobat ... apiref.pdf
And there is a dedicated section on form fields and what you can do with them.

Kind regards,
Stefan