Drop down menu problem

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Drop down menu problem

Post 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
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Drop down menu problem

Post by papa »

You need to use JS:

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


And then an if statement in PHP
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: Drop down menu problem

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: Drop down menu problem

Post 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?
flaming
Forum Newbie
Posts: 12
Joined: Tue Oct 21, 2008 9:57 am

Re: Drop down menu problem

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Drop down menu problem

Post by onion2k »

Moved to clientside.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Drop down menu problem

Post 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
}
?>
Post Reply