Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Thread Tools Display Modes
Old 06-16-2012, 02:01 PM   #1
Sean Hall
Join Date: Jun 2012
Posts: 1
Default Would this work?

I am new to PHP, this is my first script I have made without any help, I am using xammp to test my site, but the basics of the code is this. I am adding an include code into the navigation menu and in the CSS I have defined certain rules for the nav. Now in the code when you click on one of the links, it will change the variable to a corresponding number. The Code is pretty much self explanatory.

PHP Code:
      <li><a href="#"  onclick="<? $active 1?>" class="<? if ($active 1){?>#navigation ul li a.active<? ?>">home</a></li>
      <li><a href="#"  onclick="<? $active 2?>" class="<? if ($active 2){?>#navigation ul li a.active<? ?>">about us</a></li>
      <li><a href="#"  onclick="<? $active 3?>" class="<? if ($active 3){?>#navigation ul li a.active<? ?>">services</a></li>
      <li><a href="#"  onclick="<? $active 4?>" class="<? if ($active 4){?>#navigation ul li a.active<? ?>">portfolio</a></li>
      <li><a href="#"  onclick="<? $active 5?>" class="<? if ($active 5){?>#navigation ul li a.active<? ?>">contact</a></li>
Now what I want to happen is when you click on one of the links, it will change to active, changing the color of the text to tell the visitor that, that link is active. Now normally I would do it though CSS, changing the texts rule to the active, but in order to be able to change buttons without having to do it though all the pages and also because I want to start using PHP more.

The Include works, as you can see below, but the code above does not work, because the home button should be a light yellow color.

Image will be added soon.....

Last edited by Sean Hall; 06-16-2012 at 02:06 PM..
Sean Hall is offline   Reply With Quote
Old 06-18-2012, 07:10 AM   #2
Corrosive's Avatar
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103

Not sure about the code as I only dabble in PHP as well but I thought the syntax for opening a line of PHP is <?php and not just <?
Corrosive is offline   Reply With Quote
Old 06-18-2012, 09:48 AM   #3
davidj's Avatar
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256

If your implementing this through php alone you will have to pass a flag to tell PHP which one to mark as active.

I suggest looking at JQuery for menus. By all means implement and include using PHP but for the mechanics I would use JQuery.
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 09:04 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com