How to display a hidden inputfield with select

  css, html, html-select, javascript

I’m trying to use select to display a hidden input field. With option 2 I want to show the input field and with option 1 I want to hide it again.

Does anyone know what I need to change in the code?

Thanks in advance

function showFooField() {
            document.getElementById("nameFoo").style.display = "block";
        }
#nameFoo {
  display:none;
}
 <select onchange="showFooField()" name="foo" id="foo" class="form-control">
             <option value="1" selected>1</option>
             <option value="2">2</option>
  </select>
  
    <div id="nameFoo">
        <input id="name" required />
     <div>                                

Source: Ask Javascript Questions

LEAVE A COMMENT