Copy link to clipboard
Copied
I have radio boxes named 1,2,3,4. I have them set as Yes or No and their value as Choice1/Choice 2.
When a person checks no, I need specific text to store to an array. (Each check box goes to a question and I need the question they checked no to to display later).
At the end, I want to program an action button to display an app.alert that shows the questions that someone checked no to.
For example, if they said no to questions 2 and 4. I want the app alert to display a message that says, you chose No for Do you smoke and Do you drink.
I have combined some code, and I'm not sure if I'm on the right track. I'm new to Java Script and have been looking at other people's questions.
if (getField("1").value=="Choice2") {
var question68 = "You check no for question 68";
}
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
{
if (f.required && f.value == "") {
emptyFields.push(this.getNthFieldName(i));
}
}
}
if (emtpyFields.length > 0) {
// display an error message based on the emptyFields array
}
Please help! Thank you in advance.
1 Correct answer
Here is what I ended up doing:
var questions = [
'Question 1: Do you smoke?',
'Question 2: Do you drink?']
//I had 69 questions total that I added to the above array
// the number of radio buttons you have in the pdf
var question = 79;
//question starts at checkbox 5. I made the mistake of taking out questions so my radio button started at 5.
var counter = 5;
var myArray = [];
var arraycounter = 0;
for (; counter < question; counter++) {
if (getField(counter).value=="No") {
myArray[arraycounter] = questi
...Copy link to clipboard
Copied
First, I think you should rename your fields to something other than plain numbers. Such as Q1, Q2, Q3 etc.
Next, what do empty fields have to do with this ? There is no such thing as an empty radio button. A radio button group is either the export value of the selected button, or "Off" when nothing is selected.
Does the export value of "Choice2" equate to a No selection?
The loop needs to be over the radio button groups, not all fields on the form.
Consider setting the export value for the No choice to the message text, then you get the messages automatically through the value.
What Message do you want if there is no Yes/No selection?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Here is what I ended up doing:
var questions = [
'Question 1: Do you smoke?',
'Question 2: Do you drink?']
//I had 69 questions total that I added to the above array
// the number of radio buttons you have in the pdf
var question = 79;
//question starts at checkbox 5. I made the mistake of taking out questions so my radio button started at 5.
var counter = 5;
var myArray = [];
var arraycounter = 0;
for (; counter < question; counter++) {
if (getField(counter).value=="No") {
myArray[arraycounter] = questions[counter-5];
//variable for question string
arraycounter ++;
}
}
app.alert('These questions were answered no: \n'+ myArray.join("\n"),3);
Copy link to clipboard
Copied
Have you checked the Acrobat JavaScript console for any errors?
If possible can you provide a link to the PDF form or a sample form with the problem?
As noted, it is not a good practice to use a number for a field name Acrobat/Reader or another person may confuse the numbered field name as a numeric value instead of a field or string value. Note that JavaScript does convert numbers entered as a string to numbers and this could very easily happen to your field names. There are times when sequential field names are computed and the best practice is to create an index variable for the sequential number and then concatenate that value into the base field name to string to arrive at the desired field.
Copy link to clipboard
Copied
I have checked the debugger and found no errors.
I'm not sure how to attach the PDF or link?
Copy link to clipboard
Copied
Does this code work?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
It worked for me.

