'HTML5 Extra info dropdown box

Looking for some help. Quite new to HTML5 coding. Hopefully this is possible. I want a user to answer a question with a Yes/No drop down menu, if the users selects Yes it'll populate a text box to add info.

Does anyone have any example code?

Tried multiple Yes/No Switches



Solution 1:[1]

var textbox = document.getElementById('textbox');
document.getElementById('dropdown').onchange = (e) => {
  textbox.value = "";
  if (e.currentTarget.value == "Yes") {
    textbox.value = "Populated";
  }
};
<select id="dropdown">
  <option selected>Select an option</option>
  <option value="Yes">Yes</option>
  <option value="No">No</option>
</select>
<input id="textbox" type="text"/>

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 Halden Collier