These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Set up a form to skip a question depending on the answer of another?

CHM
Registered: Jan 27 2011
Posts: 2

I have form in Adobe Standard 9: I would like to have the form 'lockout' followup questions or 'skip' to the next question, if the answer to the previous question is X.
 
Example:
Question 1: Are you reporting a problem? Yes or No (Choose from a Combo Box)
 
If the answer is "Yes" the user answers questions 1a, 1b, etc.
If the answer is "No" the user either cannot answer 1a, 1b, etc. or is authomatically directed to question 2.
 
thank you

My Product Information:
Acrobat Standard 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You could use something like the following as the combo box's custom Validate script:

// Validate script for combo box
(function () {

// Get references to the secondary fields
var f1 = getField("1a");
var f2 = getField("1b");
var f3 = getField("1c");
// Continue for as many fields as needed

// Reset the fields
resetForm([f1.name, f2,name, f3.name]);

switch (event.value) {

case "Yes":
f1.display = display.visible;
f2.display = display.visible;
f3.display = display.visible;
break;
case "No":
f1.display = display.hidden;
f2.display = display.hidden;
f3.display = display.hidden;
break;
}

})();



This code could be simplified a lot if you use a hierarchical naming convention for the secondary fields. Something like: 1.a, 1.b, 1.c, etc. If you'd like help with that, post again.
CHM
Registered: Jan 27 2011
Posts: 2
George,
Thank you for the quick reply!
Always willing to accept simplified code. I have renamed the fields - hopefully they conform to the hierarchical naming convention you are thinking of:

3.Exp (yes/no combo box)
If no, then block or skip these questions: 3.BP, 3.MA, 3.DE, 3.PO. 3.LA, 3.NM, 3.OT, 3.a, 3.bS,3.bCR, 3.bT, 3.bR, 3.bCO, 3.bN, 3.c

If skipping the questions, then goto 4.0

Chuck
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
First change the name of the combo box to "3_Exp", since we don't want to control that field with the code, just the secondary fields. The code could then be simplified to:

// Validate script for combo box
(function () {

// Specify the prefix of the secondary fields
var f_name = "3";

// Get a reference to the secondary fields
var f = getField(f_name);

// Reset the secondary fields
resetForm([f_name]);

// Show or hide the secondary fields based on the combo box selection
switch (event.value) {

case "Yes":
f.display = display.visible;
break;
case "No":
f.display = display.hidden;
break;
}


})();


If you want to reuse this code for use by multiple combo boxes, create a document-level function (Advanced > Document Processing > Document JavaScripts) and add the function:// Validate script for combo box
function controlChildren(f_name) {

// Get a reference to the secondary fields
var f = getField(f_name);

// Reset the secondary fields
resetForm([f_name]);

// Show or hide the secondary fields based on the combo box selection
switch (event.value) {

case "Yes":
f.display = display.visible;
break;
case "No":
f.display = display.hidden;
break;
}
}


Call this function from the Validate event of the combo box like this:

controlChildren("3");


Replace the "3" in the function call with the prefix of the secondary fields. For example, for question #4 that you've set up similarly, it would be:

controlChildren("4");


Unfortunately, the forum won't show formatted code, but I hope you get the idea.