Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
That didn't work. The radio grouping is Group3.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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"
Copy link to clipboard
Copied
Please ignore the email for now. Lets just get the validation part figured out first.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You'll need to share your file for further help.
Copy link to clipboard
Copied
And you need to explain the conditions under which the message should be displayed.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
- 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"
Copy link to clipboard
Copied
- 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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.");
}
Copy link to clipboard
Copied
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.