简体   繁体   中英

Adobe Acrobat Pro - Drop down list, show and hide values in javascript

I am using Adobe Acrobat Pro for my PDF form. I would like to hide and show values, depending on the values selected in the drop down box.

My problem. I need to select the same value twice, before it actually functions the way i want. It seem like it does not get the selected value immediately.

The drop down box is working, it's just the JavaScript for hiding and showing values that is not working properly.

Any help would be appreciated.

(function () {
var v = getField("Combo Box2").value; 
if (v === "031 Rotvoll Bygg A") {
    this.getField("ByggC").display = display.hidden;
    this.getField("ByggA").display = display.visible;
    return;
} else if (v === "033 Rotvoll Bygg C") {
    this.getField("ByggA").display = display.hidden;
    this.getField("ByggC").display = display.visible;
    return;
} else {
    this.getField("ByggA").display = display.visible;
    this.getField("ListBox2").display = display.visible;
    this.getField("ByggC").display = display.visible;
    return;
}

})();

In the options panel, check the box that says "Commit selected value immediately" then add your code to the Custom Format Script of the dropbox but don't wrap it in a function. It should be just...

var v = this.getField("Combo Box2").value; 
if (v === "031 Rotvoll Bygg A") {
    this.getField("ByggC").display = display.hidden;
    this.getField("ByggA").display = display.visible;
} else if (v === "033 Rotvoll Bygg C") {
    this.getField("ByggA").display = display.hidden;
    this.getField("ByggC").display = display.visible;
} else {
    this.getField("ByggA").display = display.visible;
    this.getField("ListBox2").display = display.visible;
    this.getField("ByggC").display = display.visible;
}

The custom format script runs only when the value changes so that's when you'll know the drop box value has the value you selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM