logo-dw

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

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

Hello,
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:
<?
$active 
1;
?>    
    <ul>
      <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>
    </ul>
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 03:06 PM..
Sean Hall is offline   Reply With Quote
Old 06-18-2012, 08:10 AM   #2
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

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, 10:48 AM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

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
Reply


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 08:45 PM.


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