Programatically changing dropdown menu selection items?

My student wants to take the input from a series of 5 text input fields and populate a dropdown menu with them. He has assigned the input string values to assignment1, assignment2, etc.

We have tried many approaches, but I don’t even know if this is possible at this point. Ideas? (Code we have tried is below. Console.log is showing that the assignmentX variables are picking up the input values from the text input fields.

setProperty(“dropdown_first”,“value”, assignment1, assignment2, assignment3, assignment4, assignment5);
//setText(“dropdown_first”, assignment1, assignment2, assignment3, assignment4, assignment5);
//dropdown(“dropdown_first”, assignment1, assignment2, assignment3, assignment4, assignment5);
//getProperty(“dropdown_first”,assignment1, assignment2, assignment3, assignment4, assignment5);
getProperty(“dropdown_second”,“options”, assignment1, assignment2, assignment3, assignment4, assignment5);
getProperty(“dropdown_third”,“options”, assignment1, assignment2, assignment3, assignment4, assignment5);
getProperty(“dropdown_fourth”,“options”, assignment1, assignment2, assignment3, assignment4, assignment5);
getProperty(“dropdown_fifth”,“options”, assignment1, assignment2, assignment3, assignment4, assignment5);

@nicholsonl

Your first line was almost there! Here is my test program:
var str = prompt(“Enter a value”);
setProperty(“dropdown1”, “options”, [“select”, str]);

Happy computing!
Andrea

1 Like

Is there a way to populate the dropdown options with the contents of a list(array) in code studio?

Hi @jmay1 ,

It looks like you might be able to using the setProperty function as mentioned above to change an existing dropdown, or look into the “dropdown” function to create a dropdown and populate it using a list - documentation for “dropdown” function

Looks like the dropdown function takes in multiple strings, so you may have to reference the array like so…


Doing this with an array of any size gets more complicated (honestly haven’t really thought about how/if it can be done, but let us know if that’s what you need and you’d like help figuring it out).

assign all list entries to a drop down menu like this:

setProperty(“birds.ddl”, “options”, bird_names_lst);

1 Like

With that, we are running into the problem of the dropdown being all in 1 line versus separating vertically by index. Is there something I’m missing?

Hi @kmi8961 ,

Can you please click “Share” in the upper left of the student project and paste the link here? That will help us make sure we are debugging the same program you are referring to.

Thank you!
–Michael K.