Put input inside select

Viewed 30562

Is there a way to place an INPUT field inside select?

<select name="menu_files" class="form-control" >
    <option value="new_menu"> <input type="text"></option>
</select>
4 Answers

<datalist> Element

The datalist element is intended to provide a better mechanism for this concept.

<input type="text" name="example" list="exampleList">
<datalist id="exampleList">
  <option value="A">  
  <option value="B">
</datalist>

For more information, see

We can achive it putting the input tag "next to" and not "inside" the select tag but forcing them into a limited and fixed area like a table td.

function selection(){
 var selected=document.getElementById("select1").value;
  if(selected==0){
   document.getElementById("input1").removeAttribute("hidden");
  }else{
   //elsewhere actions
  }
}
td{
  width: 170px;
  max-width: 170px;
  overflow: hidden;
  white-space: nowrap;
}

input{
  width: 164px;
}
<table>
  <tr>
      <td>
        <input id="input1" hidden="hidden" placeholder="input data">
        <select onchange="selection()" id="select1">
          <option value="-1"></option>
          <option value="0">-make your own choice-</option>
          <option value="1">choice 1</option>
          <option value="2">choice 2</option>
        </select>
      </td>
  </tr>
</table>

jsfiddle

You can also code like this.

<label class="text-left text-uppercase mt-1 sidenav-text w-100" for="category" onclick="menuShow();"  >Category</label>
        <p id="demo"></p>

and in remaining js

<script>
    var demo = document.getElementById('demo');
    function menuShow(){
        demo.innerHTML = `
        <input type="radio" name="select" value="women"> Women<br>
        <input type="radio" name="select" value="women"> Men<br>
        <input type="radio" name="select" value="women"> Kid<br>
        <input type="radio" name="select" value="women"> Boy<br>    
        `;
    }
</script>
Related