This can be done, but is a bit complex. Let's assume you have one dropdown and a text field named "Text1", then do the following:
Create a document level script using the following script:
function UpdateTextField(doc, fieldName, newValue)
{
var ar = [];
// Get the values currently stored in the text field and
// convert them to an array
var v = doc.getField(fieldName).value;
if (v.length > 0) {
var ar = v.split(",");
}
// Do we already have newValue in the array?
var foundIt = -1;
for (var i=0; i<ar.length; i++) {
if (ar[i] == newValue) {
foundIt = i;
break;
}
}
if (foundIt != -1) {
// remove the item
ar.splice(i, 1);
}
else { // add the item at the end
ar.push(newValue);
}
// If we have more than four elements,
// remove the oldest one
while (ar.length > 4) {
ar.shift();
}
// conver the array to a string
this.getField(fieldName).value = ar.join();
}
In your dropdown control, go to the Options tab and make sure that "commit selected values immediately" is selected, then go to the "Validation" tab and select to use a custom validation script. Use this one line script:
UpdateTextField(this, "Text1", event.value);
As you can see, we are specifying the field name as the 2nd parameter to this function call.
This should do the trick. When you select a value that's already in the list, it will be removed, and if you select more than four values, the oldest value will be removed.
Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com