I have a checkbox that will add 5 items to a dropdown when it is clicked. I would like to be able to delete the newly added items (5 of them), when a different checkbox is selected.
Code for adding:
DropDown2.addItem("123")
DropDown2.addItem("456")
DropDown2.addItem("789")
DropDown2.addItem("ABC")
DropDown2.addItem("DEF")
I beleive that code is correct, but I am having diffuclty with removing those items. I am using "DropDown2.deleteItem", just not sure of the syntax. I know you need to specify the index in order to delete, but it is not working. Dropdown2 has 5 items already, and I'm adding an additional 5 when the checkbox is clicked. My question would be how would I delete those newly added choices? Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
You need a While loop to achieve this..
Below code should work..
var intCount = DropDown2.length;
while (intCount>5){
DropDown2.deleteItem(intCount-1);
intCount = DropDown2.length;
}
Thanks
Srini
Views
Replies
Total Likes
Try like this..
for(var i=4;i<DropDown2.length;i++){
DropDown2.deleteItem(i);
}
Thanks
Srini
Didnt work.
Choices 1-5 are the items already in the dropdown
Choices 6 -10 are the items that I am adding.
It deleted choices 5,7, and 9. Very odd, any ideas?
Just to clarrify again, i would like items 6-10 to be removed. Thanks
Views
Replies
Total Likes
You need a While loop to achieve this..
Below code should work..
var intCount = DropDown2.length;
while (intCount>5){
DropDown2.deleteItem(intCount-1);
intCount = DropDown2.length;
}
Thanks
Srini
Views
Replies
Total Likes
It worked. Thanks a bunch!
Views
Replies
Total Likes