Highlighted

Removing and printing items from the text box.

Engaged ,
Oct 26, 2020

Copy link to clipboard

Copied

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-r... 

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 ();

 

 

 

 

 

 
Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
It is necessary to remove elements from the array at the same time as removing the list elements.

Or don't use an array, but use lbx.items.
var print = w.add ("button", undefined, "Print selected items"); // why selected???
    print.onClick = function () {
     for (var i = 0; i < lbx.items.length; i++)
     alert(lbx.items[i].text);
}
 
TOPICS
Actions and scripting

Views

52

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Removing and printing items from the text box.

Engaged ,
Oct 26, 2020

Copy link to clipboard

Copied

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-r... 

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 ();

 

 

 

 

 

 
Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
It is necessary to remove elements from the array at the same time as removing the list elements.

Or don't use an array, but use lbx.items.
var print = w.add ("button", undefined, "Print selected items"); // why selected???
    print.onClick = function () {
     for (var i = 0; i < lbx.items.length; i++)
     alert(lbx.items[i].text);
}
 
TOPICS
Actions and scripting

Views

53

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 26, 2020 0
Adobe Community Professional ,
Oct 26, 2020

Copy link to clipboard

Copied

It is necessary to remove elements from the array at the same time as removing the list elements.

Or don't use an array, but use lbx.items.
var print = w.add ("button", undefined, "Print selected items"); // why selected???
    print.onClick = function () {
     for (var i = 0; i < lbx.items.length; i++)
     alert(lbx.items[i].text);
}
 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2020 1
Engaged ,
Oct 26, 2020

Copy link to clipboard

Copied

Great, it worked now! Thank you r-bin , I am happy to know that you still attend this community.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 26, 2020 0