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

Creating a Button to Flag Required Radio Buttons

New Here ,
Mar 14, 2025 Mar 14, 2025

I am creating a form for a design company; there are several radio buttons that are required for submission. I want to create a button that when clicked, shows nothing if all required radio buttons are selected. If required radio buttons have not been selected, I want a pop up stating "Please select all required radio buttons" to appear. I have searched forums for days and nothing seems to be working properly.

TOPICS
Create PDFs , JavaScript , PDF , PDF forms , Rich media and 3D
521
Translate
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 ,
Mar 14, 2025 Mar 14, 2025

Radio button groups (and check boxes) have a value of "Off" when unselected.  For example, if one of the radio button groups is named "Group1", then this code (on a button) could be used to validate a selection.

 

if(this.getField("Group1").value == "Off")

     app.alert("Please select an entry for the Group 1 Radio Buttons");

 

You can read more about radio buttons and checkboxes here:

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Mar 14, 2025 Mar 14, 2025

lauren_1216_0-1741974666269.png

lauren_1216_1-1741974694915.png

That didn't work. The radio grouping is Group3.

 

Translate
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 ,
Mar 14, 2025 Mar 14, 2025

You need to add the submit command after the if-statement, like this:

 

 

if(this.getField("Group3").value == "Off")
     app.alert("Please select an entry for the Group 1 Radio Buttons");
else this.mailDoc({cTo: "me@email.com"});

 

 

And just saying "it doesn't work" is not very useful to us. What exactly happens when you click the button? Is there an error message in the JS Console? Does anything happen at all? Be more specific, please.

Translate
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
New Here ,
Mar 14, 2025 Mar 14, 2025

Nothing happens when I select the button. I'm not much into coding so I'm trying to learn the language as I go so I apologize for my lack of knowledge, but I'm trying my best. So I don't know what a submit command is

 

Translate
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 ,
Mar 14, 2025 Mar 14, 2025

In the code I provided, the message will only be displayed if no radio buttons in the group are selected. 

If you want the message to be displayed for some other condition, then you need to tell us exactly what it is you want. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Mar 14, 2025 Mar 14, 2025

After adding else this.mailDoc.... this is now the message that comes up when I select the button, but I don't want it to email, I just want a notification box to pop up stating "Please select an entry for Group3 Radio Buttons"

lauren_1216_0-1741976011636.png

 

Translate
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 ,
Mar 14, 2025 Mar 14, 2025

Please ignore the email for now. Lets just get the validation part figured out first.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Mar 18, 2025 Mar 18, 2025

if(this.getField("Group3").value == "Off")
app.alert("Please select an entry for all Radio Buttons");

 

This is what I have and regardless of if the radio button is selected or not, the button doesn't do anything when clicked

Translate
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 ,
Mar 18, 2025 Mar 18, 2025

You'll need to share your file for further help.

Translate
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 ,
Mar 18, 2025 Mar 18, 2025

And you need to explain the conditions under which the message should be displayed.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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
New Here ,
Mar 19, 2025 Mar 19, 2025

Here is one of the files. The JavaScript covers the required text boxes, but even though the radio buttons are set to required, they are not a part of the JavaScript check. So if all text boxes are filled out but no radio buttons are selected, the app alert will not pop up when the button (logo at the bottom of the page) is selected.

Translate
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
New Here ,
Mar 19, 2025 Mar 19, 2025

I want the button to check for all require fields, whether it is a text box or a radio button, and have the app alert pop up if any of them have not been filled out or completed

Translate
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 ,
Mar 19, 2025 Mar 19, 2025

- The code in this file is not the code you posted here.

- You did not adjust the code as I've recommended in reply to your other post.

- You have an (at least one) incorrect field name in your code, namely: "Original Install_af_date"

Translate
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
New Here ,
Mar 19, 2025 Mar 19, 2025

- I have been trying the code on a document that has only radio buttons to remove the variable of the text boxes. However, this is the ultimate goal of have the code work within this document.

- I don't understand how to combine the code so that it reads it for both a text box and a radio button.

- I just had to change those yesterday based on user feedback. I have changed the names on the attached document.

 

In regards to the second point here, do I need to have a seperate JavaScript run for the radio buttons, or does it get merged with what is currently there for the text boxes?

Translate
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 ,
Mar 19, 2025 Mar 19, 2025

No, all you need (as I said before) is to change this line:

if (!field.value) {

To:

if (field.valueAsString==field.defaultValue) {

 

If the field names are corrected, the code will work fine. Although I would also add a line to hide the signature field if not all the fields are filled-in.

Translate
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
New Here ,
Mar 19, 2025 Mar 19, 2025

Wow, thank you so much for your help. I apologize for my lack of knowledge; I have been researching this for weeks and hadn't found a solution. I really appreciate your persistence with me!

 

How does one hide the signature field if no all fields are filled out?

Translate
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 ,
Mar 19, 2025 Mar 19, 2025

Change the last bit of the code to:

 

if (allFilled) {
    this.getField("Client Signature").display = display.visible; // Show the signature field
} else {
	this.getField("Client Signature").display = display.hidden; // Hide the signature field
    app.alert("Please fill in all required fields before signing.");
}
Translate
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
Adobe Employee ,
May 05, 2025 May 05, 2025
LATEST

Hi @lauren_1216,

 

Hope you are doing well.

 

Just chiming in to check if your concern is fixed.

If yes, please feel free to leave an upvote or mark the statement(s) as a correct answer for future users to use as a reference.


Regards,
Souvik.

Translate
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