There are different ways to approach this. Here is one:
Create your listbox and your text box. To calculate the value in the text box, we need a custom calculation script , so open the preferences for the text box and select the Calculate tab and select a custom calculation script.
The following script will get all selected value and add them up:
var f = this.getField("ListBox1");
var a = f.currentValueIndices;
if (typeof a == "number") { // we have a single selection
if (a == -1) { // nothing selected
event.value = "";
}
else {
event.value = Number(f.getItemAt(a, false));
}
}
else { // multiple selections
console.println("Found " + a.length + " selected values");
var sum = 0;
for (var i = 0; i < a.length; i ++) {
sum += Number(f.getItemAt(a[i], false));
}
event.value = sum;
}
Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com