# Programatically changing dropdown menu selection items?

**URL:** <https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328>\
**Category:** Uncategorized\
**Tags:** applab, dropdown\
**Created:** [March 30, 2018, 2:54pm UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328 "2018-03-30T14:54:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicholsonl](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nicholsonl](https://forum.code.org/u/nicholsonl)\
**Post date:** [March 30, 2018, 2:54pm UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328/1 "2018-03-30T14:54:28Z")

</div>

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);

---

<div class="post-metadata">

**Author:** ![anmrobnott](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/anmrobnott/32/505_2.png) [@anmrobnott](https://forum.code.org/u/anmrobnott)\
**Post date:** [March 31, 2018, 9:36pm UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328/2 "2018-03-31T21:36:16Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![jmay1](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jmay1](https://forum.code.org/u/jmay1)\
**Post date:** [February 7, 2021, 3:54am UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328/3 "2021-02-07T03:54:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![frank\_w\_lee](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/frank_w_lee/32/4895_2.png) [@frank\_w\_lee](https://forum.code.org/u/frank_w_lee)\
**Post date:** [February 7, 2021, 7:57am UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328/4 "2021-02-07T07:57:55Z")

</div>

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](https://studio.code.org/docs/applab/dropdown/)

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

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/e/e13ce2ccab2b4aae89cca00b7a2016ea39308776.png)  
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).

---

<div class="post-metadata">

**Author:** ![jim\_wunderlich](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@jim\_wunderlich](https://forum.code.org/u/jim_wunderlich)\
**Post date:** [February 15, 2022, 4:22pm UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328/5 "2022-02-15T16:22:18Z")

</div>

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

setProperty(“birds.ddl”, “options”, bird\_names\_lst);

---

<div class="post-metadata">

**Author:** ![kmi8961](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/kmi8961/32/5554_2.png) [@kmi8961](https://forum.code.org/u/kmi8961)\
**Post date:** [March 14, 2024, 10:29pm UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328/6 "2024-03-14T22:29:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mkmietowicz](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mkmietowicz/32/6322_2.png) [@mkmietowicz](https://forum.code.org/u/mkmietowicz)\
**Post date:** [March 18, 2024, 3:59am UTC](https://forum.code.org/t/programatically-changing-dropdown-menu-selection-items/15328/7 "2024-03-18T03:59:51Z")

</div>

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.
