'Editing dropdown values without having to create a new dropdown every time
Within the code.org javascript editor for the applab, there is the ability to create a dropdown by creating a dropdown by:
dropdown('id', 'option1', 'option2', ...);
I would like to know if there is a way to edit the list, treating it something like an array:
remove('id', 'position');
and:
insert('id', 'position', 'item1', 'item2'...);
any help would be appreciated, as I can't find any way to do this in other places.
Solution 1:[1]
You can convert dropdown to an array using getProperty. Then, edit the array, and convert it back to a dropdown with setProperty. Here's the code;
dropdown("id", "a", "b", "c");
function editDropdown() {
var myDropdown = getProperty("id", "options");
//add someting to your dropdown.
appendItem(myDropdown, "e");
//remove something from your dropdown.
removeItem(myDropdown, "a");
setProperty("id", "options", myDropdown);
}
editDropdown();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cengiz |
