Removing and printing items from the text box.
Greetings everyone!
After a few months of pausing in my studies, I decided to return and soon I ran into an error in the script I picked up on this one on page 31 of this manual: https://adobeindd.com/view/publications/a0207571-ff5b-4bbf-a540-07079bd21d75/92ra/publication-web-resources/pdf/scriptui-2-16-j.pdf
My question is: How to return only the items in the text box after deleting some? It prints all items even after deleting. Where's the error?
Thank you
var w = new Window ("dialog");
var array= ["one", "two", "three", "four"]
var lbx = w.add ("listbox", undefined, array, {multiselect: true});
var del = w.add ("button", undefined, "Delete selected items");
del.onClick = function () {
// remember which line is selected
var sel = lbx.selection[0].index;
for (var i = lbx.selection.length-1; i > -1; i--)
lbx.remove (lbx.selection[i]);
// select a line after deleting one or more items
if (sel > lbx.items.length-1)
lbx.selection = lbx.items.length-1;
else
lbx.selection = sel;
}
var print = w.add ("button", undefined, "Print selected items");
print.onClick = function () {
for (var i = 0; i < array.length; i++)
alert(array[i]);
}
w.show ();
