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

Variable switch

miQlo
Registered: Jul 13 2010
Posts: 44

I have three comboboxes A, B and C with one item each 1, 2 and 3 wich all trigger the "printAscend" function. How do I make the variable "x" switch place with the variable that coresponds the combobox that triggerd the function. Ex: if I select an item from combobox "C" I want the last line change to console.println(a + b + x); and they always have to be in the same order.
 
function printAscend(){
var a = this.getField("A").value;
var b = this.getField("B").value;
var c = this.getField("C").value;
var x = event.changeEx;
if(!event.willCommit){
console.println(a + b + c);
}
}
  
I have some solutions but I don't like them, I'd like to see how you do it.
 
Ex:
 
if(event.changeEx = "1"){
console.println(x + b + c);
}
else if(event.changeEx = "2"){
and so on...
   
(tabs vanished from the script when submitted?)

My Product Information:
Acrobat 9.4.1, Windows
George_Johnson
Online
Expert
Registered: Jul 6 2008
Posts: 1876
You can use event.target to get the field that triggered the script, so you can do something like:

function printAscend() {

var fa = getField("A");
var fb = getField("B");
var fc = getField("C");
var ft = event.target;

var a = ft === fa ? event.changeEx : fa.value;
var b = ft === fb ? event.changeEx : fb.value;
var c = ft === fc ? event.changeEx : fc.value;

if(!event.willCommit){
console.println(a + b + c);
}

}

But you may need to convert the field values to number or strings, depending on whether you want string concatenation or numerical addition.