Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

deleteItem on selectedIndex only deletes first Item in listbox

Avatar

Avatar
Boost 1
Level 1
rossi45
Level 1

Like

1 like

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
rossi45
Level 1

Like

1 like

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
View profile
rossi45
Level 1

28-02-2017

Hello. I am trying to create listbox that will be populated by entries from a numeric field using a button. I will have 3 buttons. An 'Add Item' button, a 'Remove Selected Item' button and a 'Clear All Items' button. I have having difficulty with the 'Remove Selected Items' button.

On the click event for the remove button, I have written some simple javascript code to delete the selected index item that should read the selected item from the listbox and then delete it.

ListBox1.deleteItem(ListBox1.selectedIndex)

This isn't happening. I have noticed that, when I click on my item in the list box, it gets highlighted in blue. When I go and subsequently click on the remove button, all of a sudden, all of the items in the listbox gets highlighted and then the first item in the list gets removed regardless of which items I had chosen. My feeling is, that the all the items in the listbox is getting selected when I press the button and so some sort of default behavior of the selectedItem method makes it grab the first item in the list. I ahve no other code on that button nor do I have any code for the listbox at all.

Not sure if I am setting up my button properly. maybe this is not the right function? Has anyone experienced this behavior?

Couple other things worth noting. The list box is empty. I do not pre-populate it with default items.

I tested the remove button by adding some default items to the list and then selecting one and then clicking the button. This seems to work so I am not sure why my user driven data is different from default data.

Accepted Solutions (0)

Answers (3)

Answers (3)

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

19-03-2017

My add item button is adding an item to the list box based on what is in a textfield. Use unique names for all fields to make referencing them easier, but you can resolveNode as well for referencing objects.

btnAdd: click (Javascript)

ListBox1.addItem(TextField1.rawValue);

I also made a get from listbox button which returns the selected item to a textfield

btnGet: click (Javascript)

TextField2.rawValue = ListBox1.rawValue;

Removing as before

btnRemove: click (Javascript)

ListBox1.deleteItem(ListBox1.selectedIndex);

Avatar

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile

Avatar
Boost 50
MVP
_Bruce_Robertson
MVP

Likes

269 likes

Total Posts

1,782 posts

Correct Reply

372 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 250
Boost 25
View profile
_Bruce_Robertson
MVP

18-03-2017

Hi,

Can you show us the code you have in the 'Add Item' button.  I assume this is using the addItem() method, but what are you using as the second parameter, or are you letting it default.  This is the 'rawValue' and must be unique across all items in the list.  If you select an item then all items with the same value will be selected and selectedIndex will return the value of the first one.  Sounds a bit similar to your problem?

Regards

Bruce

Avatar

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Validate 1
Level 4
MinusZero
Level 4

Likes

30 likes

Total Posts

326 posts

Correct Reply

54 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 25
Boost 10
View profile
MinusZero
Level 4

15-03-2017

The code you have shown is the same code i have used and it works to remove a selected item. I have made something similar in testing with populating a listbox using a field and add button/remove buttons. Not sure why it would not be working.

Maybe it is just how it is written for the post, but you are missing the semicolon at the end of the line.