Page 1 of 1

Drop down menu problem

Posted: Thu Nov 06, 2008 8:41 am
by flaming
Hi,

I'm trying to get my head a round a part of a site i'm working on, it's simple but i can't figure it out.

all i want to do i when a user selects "Other" in a drop down menu a text box appears below.

i know it could be done in javascript but i need it in php really.

any help needed please

Thank You
James

Re: Drop down menu problem

Posted: Thu Nov 06, 2008 8:59 am
by papa
You need to use JS:

<select onchange='this.form.submit()'> ...


And then an if statement in PHP

Re: Drop down menu problem

Posted: Thu Nov 06, 2008 9:14 am
by flaming
so once the user changes the option a box would appear almost instantly?

here is the php i have so far

Code: Select all

<?php
if (payment.value == "other")
{echo "<tr><td>Other:</td> <td class='input'><input type='text' name='other' /></td></tr>";}
{echo "<input type='hidden' name='other' value='N/A' />";}
?>
and the html to go with it

Code: Select all

<td>Payment:</td><td class="input"><select name="selection">
<option>--Please Select--</option>
<option value="zero">zero</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
</select></td>
</tr>
could you give me an example??

Thanks
James

Re: Drop down menu problem

Posted: Thu Nov 06, 2008 9:17 am
by shiznatix
i don't have time to answer your question right now but i hope you know that "php" you posted is well...not php. Looks like a combo of Javascript and PHP?

Re: Drop down menu problem

Posted: Thu Nov 06, 2008 9:23 am
by flaming
yeah i know it's not actual php
but i'm new to it and am still learning unfortunately

i've tried to outline what i am trying to do (with no idea on how to start it)

if you could give it a look sometime and let me know i'd be very greatful

Thanks
James

Re: Drop down menu problem

Posted: Thu Nov 06, 2008 9:28 am
by onion2k
Moved to clientside.

Re: Drop down menu problem

Posted: Thu Nov 06, 2008 9:31 am
by papa
I'll give a quick example before I call it a day:

Your form:

Code: Select all

<form method="post" action="<?php echo $_SERVER['php_self']; ?>" name="papa">
<select name="selection" onchange='this.form.submit()'>
<option vals...
</select>
 
 
<?php
 
if(isset($_POST['papa'])) {
//show my textfield
}
?>