• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Removing and printing items from the text box.

Engaged ,
Oct 26, 2020 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 ();

 

 

 

 

 

 
TOPICS
Actions and scripting

Views

242

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
community guidelines

correct answers 1 Correct answer

Valorous Hero , Oct 26, 2020 Oct 26, 2020
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);
}
 

Votes

Translate

Translate
Adobe
Valorous Hero ,
Oct 26, 2020 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);
}
 

Votes

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
community guidelines
Engaged ,
Oct 26, 2020 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.

Votes

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
community guidelines
Advocate ,
Jan 03, 2024 Jan 03, 2024

Copy link to clipboard

Copied

LATEST

How are items removed from an array. I've tried so many things but it simply won't work.

Why I test typeof(arrayName), it returns an object even though declared as array.  I believe estk tells an array to be an object.

But I can get it to work to remove an item of that array. 

Votes

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
community guidelines