Turn on or off button with combo box / dropdown

What I'm using currently is below. I have tried this in the "actions" and in the validation menu locations. They both seem to work, except, when making the selection, it randomly changes which is on or off. It doesn't seem to care what the export value I'm trying to target is.


var sh = this.getField("Shoulder").value ;
if(sh == 1) {
this.getField("s").display = display.visible ;
this.getField("gr").display = display.hidden ;
this.getField("b").display = display.hidden ;
}
else if(sh == 2) {
this.getField("s").display = display.hidden ;
this.getField("gr").display = display.visible ;
this.getField("b").display = display.hidden ;

}
else if(sh == 3) {
this.getField("s").display = display.hidden ;
this.getField("gr").display = display.hidden ;
this.getField("b").display = display.hidden ;

}

Also, on a side note, is it possible to "re-skin" or change the UI of the dropdown button?


klekampcd


3 Answers

Voted Best Answer

The correct way to code this if your items have export values is to use a custom Keystroke script, not any of the other events that you've placed the code. It could be something like:

// Custom Keystroke script

(function () {

if (event.willCommit) {
    return;
}   

var f1 = getField("s");
var f2 = getField("gr");
var f3 = getField("b");

// Get the export value of the selected item
var sh = event.changeEx;

// Show/hide the fields
switch (sh) {
case "1" :
    f1.display = display.visible;
    f2.display = display.hidden;
    f3.display = display.hidden;
    break;
case "2" :
    f1.display = display.hidden;
    f2.display = display.visible;
    f3.display = display.hidden;
    break;
case "3" :
    f1.display = display.hidden;
    f2.display = display.hidden;
    f3.display = display.hidden;
    break;
default :
    // If some other combo box item is selected
    // add additional code
    break;
}

})();

But since this will get misformatted by the forum software, here's what it really should look like: http://pastebin.com/8Uq3FJEb

Before I was trying to get you to realize that your variable sh wasn't getting assigned the value you were expecting.


By George Johnson   

Add this line after the first one:

app.alert(sh);

Does it display what you're expecting the value to be?


George Johnson   

You should be using event.value instead of this.getField("Shoulder").value ... So the first line should be:

var sh = event.value;

And if you want to be sure it's a number then use this:

var sh = Number(event.value);

Also, make sure you enable the option to commit the field's selected value immediately (under Properties - Options).

And no, you can't "skin" the appearance of the drop-down button.

.


Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67)   


Please specify a reason: