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

Conditional hiding of ComboBox

BAWD001
Registered: Jan 21 2009
Posts: 47
Answered

My Acrobat PDF form requires conditional processing based on the input value of a ComboBox.

The first ComboBox (nStair_Depth) has two values; 10 or 12 (default = 10). Its value determines the visibility of two other ComboBoxes.

If nStair_Depth = 10, ComboBox (nPlatform_Depth10) should be visible with a default value of 30.

If nStair_Depth = 12, ComboBox (nPlatform_Depth12) should be visible with a default value of 30.

P.S. These nPlatform_Depthx ComboBoxes have different selectable item list values with overlap on only two common values; 30 and 60.

In the Actions dialog for the nStair_Depth ComboBox I've create an Action with Select Trigger = Mouse Up, Select Action = Run a JavaScript and I entered the following JavaScript code:

if (this.getField("nStair_Depth").value==10)
{
this.getField("nPlatform_Depth12").display = display.hidden;
this.getField("nPlatform_Depth10").display = display.visible;
this.getField("nPlatform_Depth10").value = 30;
}
else
{
this.getField("nPlatform_Depth10").display = display.hidden;
this.getField("nPlatform_Depth12").display = display.visible;
this.getField("nPlatform_Depth12").value = 30;
}

At startup the nStairs_Depth ComboBox is displayed with a default value of 10, the nPlatForm_Depth10 ComboBox is visible with a default value of 30 and the nPlatform_Depth12 ComboBox is hidden with a default value of 30. Good.

However, changing the value of nStair_Depth from 10 to 12 does not immediately change the visibility of the nPlatform_Depthx ComboBoxes. However, if I re-enter the nStair_Depth ComboBox and re-select 12, then the code executes, the nPlatform_Depth10 ComboBox becomes hidden, the nPlatform_Depth12 ComboBox becomes visible and the default value of 30 is displayed. Switching back to 10 from 12 requires the same re-select process to show the appropriate nPlatform_Depth10 ComboBox with it's default value of 30.

Ideally, I'd like it function as follows:

Only on actually "changing" the nStairs_Depth value does the appropriate nPlatform_Depthx ComboBox appear immediately (without any extra manipulation of the nStair_Depth field as described above). If I simply select the nStair_Depth field, nothing should happen unless I actually "change" the value.

Upon changing the nStair_Depth value, if the previous nPlatform_Depthx value was 30 or 60 it should become the new value for the newly visible nPlatform_Depthx ComboBox ... otherwise the default value of 30 should be set. I know the reset-value logic is different from the ComboBox visibility issue but I'll eventually need to deal with both issues.

This visibility problem seems to me to be a function of finding the proper way to trigger the execution of the Run Javascript event to coincide with an actual "change" to the value of the NStair_Depth field and no other event.

Any suggestions would be greatly appreciated.

My Product Information:
Acrobat Standard 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You need to be using the Keystroke event of the combo box and change the code a bit. Try the following as the first combo box's custom Keystroke script:

(function () { // Get references to the other combo boxesvar f1 = getField("nPlatform_Depth10");var f2 = getField("nPlatform_Depth12"); // When the user makes a selection...if (!event.willCommit) { // Get the export value of the selected itemvar val = event.changeEx; if (val == 10) { f1.display = display.visible;f1.value = 30;f2.display = display.hidden; } else { f1.display = display.hidden;f2.display = display.visible;f2.value = 30;}} })();

For more information on working with combo boxes and JavaScript, see Thom Parker's articles in the Tutorial section here. Here is a link to the first one: http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle/

George
BAWD001
Registered: Jan 21 2009
Posts: 47
Thank for the information George.

I couldn't find where to put the code in my Acrobat 9 Standard software to access the Keystroke event of the combo box. Options available in the Combo Box Properties|Actions tab are Mouse Up, Mouse Down, Mouse Enter, Mouse Exit, On Focus and On Blur ... no mention of "Keystroke".

I looked at the Thom Parker article you provided a link to. In the Acroform solution section, it references requiring Document Level scripting for this kind of coding (as opposed, I assume, to coding at the Combo Box object level) and provided a link (http://www.acrobatusers.com/tutorials/2007/07/js_document_scripts/).

Following the link to the July 20, 2007 article "Entering Document Scripts" it mentions to create those scripts by accessing the Advanced>JavaScript>Document JavaScripts … menu.Unfortunately, my Acrobat 9 Standard software does not have a Advanced>JavaScript menu. It has an Advanced menu but JavaScript does not show up anywhere (not even grayed out ... chuckle).Perhaps there's a different way to access document level scripting in Acrobat 9 Standard, but I can't find it.

Do you George, or anyone else, know how to access document level scripting in Acrobat 9 Standard.

Thanks.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Yes, where you go to place a custom Keystroke script can be a bit hard to find. First open the "Combo Box Properties" window, click on the Format tab, select a format category of Custom, and you will see where you can enter a custom Keystroke script.

This does not need to be placed in a document-level script, but it's not a bad idea. THom also has at least one article that discusses the subject: http://www.acrobatusers.com/tutorials/2007/07/js_document_scripts

In Acrobat 9 Pro, the menu item is "Advanced > Document Processing > Document JavaScripts".George
BAWD001
Registered: Jan 21 2009
Posts: 47
Thanks George, that solved the issue!

I'm sure I can solve the conditional requirement of resetting the newly active nPlatform_Depth12 value to 30 if the previous nPlatform_Depth10 value was not 30 or 60 ... and vice-versa.

Thanks again.

Brian