I need a piece of javascript that will hide OR show a text box IF a certain thing is selected from the dropdown. DROPDOWN: <select name="stuff" class="textField"> <option value="" selected="selected" class="textField">-select one-</option> <option value="1" <? if($starts==1){echo"selected";}?>>one </option> <option value="2" <? if($starts==2){echo"selected";}?>>two</option> </select> HTML: When option "2" is selected a text box needs to appear next to the dropdown <input name="anotherthing" type="text" class="box" value="" /> HTML: Can it be done?
I've done it! Found this <script type="text/javascript"> function toggleField(val) { var o = document.getElementById('other'); (parseInt(val) == 99)? o.style.display = 'block' : o.style.display = 'none'; } </script> and the form: <form action="" method="post"> <select name="sel" id="sel" onChange="toggleField(this.value);"> <option value="0">Select</option> <option value="1">One</option> <option value="2">Two</option> <option value="99">Other</option> </select> <input type="text" name="other" id="other" style="display: none;"> </form> HTML: