# Opening a webpage when a selection is made in a dropdown menu

**URL:** <https://forum.code.org/t/opening-a-webpage-when-a-selection-is-made-in-a-dropdown-menu/37125>\
**Category:** Coding and Debugging Help\
**Tags:** dropdown\
**Created:** [October 26, 2022, 4:19pm UTC](https://forum.code.org/t/opening-a-webpage-when-a-selection-is-made-in-a-dropdown-menu/37125 "2022-10-26T16:19:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbouza](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bbouza](https://forum.code.org/u/bbouza)\
**Post date:** [October 26, 2022, 4:19pm UTC](https://forum.code.org/t/opening-a-webpage-when-a-selection-is-made-in-a-dropdown-menu/37125/1 "2022-10-26T16:19:50Z")

</div>

First time poster.

My students are trying to get a different webpage to open when they make a selection in a dropdown menu. They have tried to use the onclick function, but that opens it when you open the menu, they have also tried using the “change” function. but that opens the same webpage when you make any selection.

I think they need to use an if function and open a webpage if the index of the item is a certain number, but we aren’t getting it to work.

Anyone able to help?

---

<div class="post-metadata">

**Author:** ![wutadam](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/wutadam/32/7711_2.png) [@wutadam](https://forum.code.org/u/wutadam)\
**Post date:** [October 26, 2022, 4:25pm UTC](https://forum.code.org/t/opening-a-webpage-when-a-selection-is-made-in-a-dropdown-menu/37125/2 "2022-10-26T16:25:59Z")

</div>

They’re on the right track with `change`. What I’ve done before is I’ve used a “Select Action…” option as the first one when doing stuff like post options on [WUT] World. When the dropdown changes, it’ll perform the selected action (such as Edit or Delete) and set the dropdown back to Select Action. Here’s an example:

```javascript
onEvent("dropdown_id", "change", function () {
  switch (getProperty("dropdown_id", "index")) {
    case 1:
      open("first website");
      break;
    case 2:
      open("second website");
      break;
    // ...
  }
  setProperty("dropdown_id", "index", 0);
});
```

---

<div class="post-metadata">

**Author:** ![bbouza](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bbouza](https://forum.code.org/u/bbouza)\
**Post date:** [October 26, 2022, 4:45pm UTC](https://forum.code.org/t/opening-a-webpage-when-a-selection-is-made-in-a-dropdown-menu/37125/3 "2022-10-26T16:45:02Z")

</div>

That worked great, thanks!!
