+ Reply to Thread
Results 1 to 3 of 3

Thread: javascript text class change for heading

  1. #1
    jakeselectronics is offline x10Hosting Member jakeselectronics is an unknown quantity at this point
    Join Date
    Mar 2009
    Posts
    38

    javascript text class change for heading

    I am changing my site over to use php includes to make it easier to update as the site grows.

    I have come across an issue.

    I have a menu and say for instance i am on the home page. 'Home' will be in lighter text because of a different class used for the home page.

    When you move onto another page, say for instance the contact page. the text 'Contact' will now be lighter...

    But using a php include file for the menu prevents me from changing the colour/shade of the text depending on which page your on becasue the menu will be universal.

    Or can I still use 1 php include file for the menu, and change the text class (to change text shade) depending on which page i am on.
    Like an If statement in the include...
    Code:
    <td>
    <a href="index.html" class="************">Home</a>
    </td>
    example: If on home page, show light text. else show dark text

    Check out my site to see how it performs now... How do i acheive the same result using an include file for the menu.
    Can this be done with javascript?




    Edit:
    Never mind....
    I worked it out.
    Found a code here perfect for what i needed...
    http://www.maketemplate.com/menu/
    Last edited by jakeselectronics; 10-17-2009 at 12:03 AM. Reason: Automerged Doublepost

  2. #2
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: javascript text class change for heading

    I would do it inside php. For instance, in each page, I'll set a variable named 'rootMenuActive':
    PHP Code:
    <?php
    //a page in your website
    $rootMenuActive 'home';
    // ...
    // the rest of the page code
    ?>
    Then in the header.php file, I'd use if statements to find which root menu should be activated:
    PHP Code:
    <?php
    // header.php

    echo "menu code...";
    if (
    $rootMenuActivate 'home') {
       echo 
    '<a href="index.html" class="************">Home</a>';
    } else {
       echo 
    '<a href="index.html">Home</a>';
    }
    // .. 
    ?>
    This code is very rudimentary, and you can improve it easily.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: javascript text class change for heading

    $_SERVER[ 'PHP_SELF' ] gives you the path to the current script.

    That lets you figure out which link to give the special class to. (personally, I do not like the link to be active at all).

    PHP Code:

    # array of arrays with  LINK_TEXT and LINK_PATH
    # add to array as site grows, etc


    $pages = array( 
                 array( 
    'Home' '/index.php' ) , 
                 array( 
    'Links' '/lynx.php' ), 
                 array( 
    'Test' '/phptest.php' )
             ) ;

    $links = array() ;

    foreach( 
    $pages as $page ){

          if( 
    $page[1] == $_SERVER['PHP_SELF'] ){
                
    $links[] = '<a href="' $page[1] . '" class="current" >' $page[0] . '</a>' ;
          } else {
                
    $links[] = '<a href="' $page[1] . '" class="other" >' $page[0] . '</a>' ;
          }
    }
      
    # Now you can use $links to build your menu. 
    Nothing is always absolutely so.

+ Reply to Thread

Similar Threads

  1. How to change the color of the text ad? :)
    By liamar in forum Free Hosting
    Replies: 9
    Last Post: 09-29-2007, 04:06 PM
  2. Change the text ad?
    By viperxx in forum Feedback and Suggestions
    Replies: 9
    Last Post: 11-16-2006, 09:59 PM
  3. Some nice-simple JavaScript effects !!
    By careerbridge in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 07-13-2006, 08:36 AM
  4. Replies: 0
    Last Post: 09-21-2005, 03:49 AM
  5. Customizing input text boxes
    By wizeman in forum Tutorials
    Replies: 0
    Last Post: 06-11-2005, 04:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers