Drop Down Styles...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Drop Down Styles...

Post by Dale »

How do i make a drop down thing select a colour...

Example:

(Drop Down Menu):
[ Green ]
| Blue | <-- I select Blue
[ Red ]

Then when i select my colour the INCLUDE tag on my page changes...

Include tag:

Code: Select all

&lt;?php include ("./colour/$sc"); ?&gt;
<b>$sc</b> being the colour selected.

Is it possible to do that?
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Post by phpPete »

If you want to change the include() arguments on the page you are currently displaying, you can't, since by the time you see the page, PHP is done with it's processing for that page on the server, so you're viewing the finished page in your browser, the client.

You can simulate it by having the page post back to itself when you select a color, passing the selected value.
Last edited by phpPete on Sun Sep 22, 2002 7:11 am, edited 1 time in total.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

ok...
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

you will need some JS for this:

Code: Select all

<form method="post" action="thispage.php" name="foo">
<select name="cs" onChange="javascript:document.foo.submit();">
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="red">Red</option>
</select>
</form>
<?
if(isset($_POST&#1111;'cs']))&#123;
include("./colour/$cs");
&#125; else &#123;
include("./colour/blue"); // DEFAULT
&#125;
?>
yeah, or something like that, you'll need javascript though.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Don't forget to add a submit button in some <noscript></noscript> tags for those people who don't have (or don't want) javascript.

Mac
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

ok thx ;)
Post Reply