Display only the items selected in a list box

I created a list box with 20 items. Once the user has selected their 7 items, I want only those 7 items to be displayed on the form. How do I accomplish this?


Tina Robinson


2 Answers

What do you mean by "be displayed on the form"? How do you want to display these selected items? Keep in mind that nobody here has seen your form, so something that might be pretty obvious to you is a complete mystery to us.


Karl Heinz Kremer   

That is how a listbox works. You can then retrieve the selected items from the form field.

However, if you really want to modify the list box contents, I would add a button to trigger that process (otherwise, you will end up with users accidentally deleting the list box content or major portions of it). You can then use something like this script as the button action:

var newList = [];
f = this.getField("ListBox1");
var a = f.currentValueIndices;
if (typeof a == "number")     // A single selection
    newList.push(f.getItemAt(a, false));
else {     // Multiple selections
    for (var i = 0; i < a.length; i ++) {
        newList.push(f.getItemAt(a[i], false));
    }
}

f.setItems(newList);

Again, this is not how list boxes normally work, and I would advise against modifying what people expect the behavior to be.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


Karl Heinz Kremer   


Please specify a reason: