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!
How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
- Tracker Supp-Stefan
- Site Admin
- Posts: 17948
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?
Hello bram147,
Please take a look at the attached file: 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:
Please take a look at the attached file: 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:
Re: How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?
Thank you very much! That's very helpful!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
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?
- Tracker Supp-Stefan
- Site Admin
- Posts: 17948
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
- Contact:
Re: How do I write the JavaScript code so that when a radio button is checked, another one gets checked as well?
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
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