Christmas Ecards - Debt Consolidation - Find jobs - Magnetic Bead Bracelet - Debt Consolidation

PDA

View Full Version : I need a piece of java that will hide OR show a text box if


x0x
Aug 23rd 2008, 7:24 am
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>

When option "2" is selected a text box needs to appear next to the dropdown

<input name="anotherthing" type="text" class="box" value="" />

Can it be done?

x0x
Aug 23rd 2008, 8:29 am
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>