Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to create an Other option with Javascript that causes a textbox to appear

Tried to create an Others option in a drop down menu, which by doing so, activates a textbox to type in.
However, my current method of doing this causes the remaining options to be invisible when clicked, and the textbox does not appear when the Others option is clicked.

function disappear(val) {
  var textbox = document.getElementById('issue');
  if (val == 'other') {
    textbox.style.display = 'block';
  } else {
    textbox.style.display = 'none';
  }
}
<select name="issue" id="issue" onchange='disappear(this.value)'>
  <option disabled selected></option>
  <option value="bug">Bug</option>
  <option value="lacking">Lack of Use</option>
  <option value="other">Other</option>
</select>
<div id="textbox"></div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you are selecting the wrong element

var textbox=document.getElementById('textbox');

function disappear(val){
          var textbox=document.getElementById('textbox');
          if(val=='other'){
            textbox.style.display='block';
          }
          else{
            textbox.style.display='none';
          }
        }
#textbox{
width:90px;
height:60px;
background-color:red;
display:none;
}
<select name="issue" id="issue" onchange='disappear(this.value)'>
          <option disabled selected></option>
          <option value="bug">Bug</option>
          <option value="lacking">Lack of Use</option>
          <option value="other">Other</option>
</select>
<div id="textbox"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading