Forum Moderators: coopster

Message Too Old, No Replies

php form with select option "Other"

php form with select option "Other"

         

phpbegginer

4:51 am on May 21, 2007 (gmt 0)

10+ Year Member



hello,

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>

vincevincevince

5:23 am on May 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Better use javascript for that, and change .style.display from 'hidden' to 'block'

phpbegginer

5:25 am on May 21, 2007 (gmt 0)

10+ Year Member



can u show me some example, i really need it fast,
i'm searching in javascript for weeks but seems not really good.

colandy

12:19 pm on May 21, 2007 (gmt 0)

10+ Year Member



This is my reply to you on the Javascript postings.

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">
...........