Forum Moderators: coopster
i have to create a php form, where there is multiple selection on the select option, when we select other, how to get a visibl text box where user can key in the other description?
sample of code need to alter.
<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF'];?>"> <p>
<select name="select">
<option value="please select one">Please select one</option>
<option value="car">car</option>
<option value="bike">bike</option>
<option value="other">other</option>
</select>
<input type="text" name="textfield">
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
try the following-
javascript function as follows:
function changeSelect()
{
var mdiv=document.getElementById('other');
var cdiv=document.getElementById('select');
if(cdiv.options[cdiv.selectedIndex].value=='other')
{
mdiv.style.visibility='visible';
}
else
{
mdiv.style.visibility='hidden';
}
}
HTML as follows:
.......
<select id="select" name="select" onChange="changeSelect()">
<option value"please">Please Select One</option>
<option value="car">Car</option>
<option value="bike">Bike</option>
<option value="other">Other</option>
</select>
<INPUT id="other" type="text" name="other">
...........