JSFiddle - React, Tailwind, and code Playground

by LimitedWard

HTML

<div id="refertodiv">
   <label for="referto">Refer to:</label>
   <select multiple="multiple" name="referto" id="referto">
     <option value="1">Infection Control</option>
     <option value="2">Medical</option>
     <option value="3">Nursing Administration</option>
     <option value="4">Personnel</option>
     <option value="5">Quality Committee</option>
     <option value="6">Risk and Safety</option>
     <option value="7">Other</option>
   </select>
</div>

JavaScript

$("#referto").change(function(){
    var otherSelected = false;
    $('#referto option:selected').each(function(){
       if ($(this).text() == "Other")
       {
           otherSelected = true;
       }
    });
    if (otherSelected)
    {
        var textarea = "<textarea name='referother' id='referother' />";
        $("#referto").after(textarea);
    }
    else
    {
        $("#referother").remove();
    }
});