-2

I need a Dropdown list with others option which allows us to add value manually if the user's field is not in a dropdown list. is it possible?

Thanks in advance, Balaji

1 Answers1

0

Even though it is a duplicated question, let me give you a direct method using plain JavaScript and HTML. Check and let me know

function myFunction() {
      var x = document.getElementById("mySelect").value;
      var input = document.getElementById("others-text");
      if (x === "others") {
        input.style.display = "block";
      } else {
        input.style.display = "none";
      }
    }
<div>
      <select name="select" id="mySelect" onchange="myFunction()">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="others">Others</option>
      </select>
      <input
        style="display: none"
        type="text"
        name=""
        id="others-text"
        placeholder="User Input"
      />
    </div>
Abin Thaha
  • 4,493
  • 3
  • 13
  • 41