Search code examples
javascriptphpjquerylaravel-4aramex

How can I create a textbox if a certain item is selected in a drop-down list?


I have a drop-down list that contains the following values:

<option>Aramex</option>
<option>DHL</option>
<option>FedEx</option>
<option>Other</option>

When the user select Other, I want to show a text box. How can I do that?

I'm using Laravel 4.2


Solution

  • here is the correct fix:

    <script type="text/javascript">
        function showfield(name){
          if(name=='Other')document.getElementById('div1').innerHTML='Other: <input type="text" name="other" />';
          else document.getElementById('div1').innerHTML='';
        }
        </script>
    
        <select name="travel_arriveVia" id="travel_arriveVia" onchange="showfield(this.options[this.selectedIndex].value)">
        <option selected="selected">Please select ...</option>
        <option value="DHL">DHL</option>
        <option value="Aramex">Aramex</option>
        <option value="FedEx">FedEx</option>
        <option value="Other">Other</option>
        </select>
        <div id="div1"></div>