stevejvan Posted July 21, 2009 Share Posted July 21, 2009 Ok, I am very new to javascript so I apologize if this is an easy fix. I have searched google, and everything I find isn't helpful. I have a portfolio site, that has an active state for each item on the nav bar using the body tag. Once you get to the portfolio page, there are genre links in addition to the nav bar links. I want to have a secondary active state for the genres, the genre code is inserted using a PHD includes statement, so there aren't multiple pages, just one main page with sections of html that change through php. I have been trying to find a way to change the body class after clicking on the secondary link. I found this code online...doesn't work. function newclass(){ document.getElementsBytagName('body')[0].id="seniors"} <a href="?page=seniors" class="genreseniors" onclick="newclass1()"> I am not sure if the body tag is the best way to go, or if i could do an if>then statement using the page=... I don't know. Any help would be appreciated. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/166834-javascript-active-state-change/ Share on other sites More sharing options...
RichardRotterdam Posted July 22, 2009 Share Posted July 22, 2009 Seeing this: I want to have a secondary active state for the genres, the genre code is inserted using a PHD includes statement, so there aren't multiple pages, just one main page with sections of html that change through php. (PHD include gimme one of those please) In that text it looks like your using the php include function. You can't use the include clientside unless you're using ajax. your hyperlink <a href="?page=seniors" class="genreseniors" onclick="newclass1()"> Here it shows that your hyperlink action will load the same page again with url parameters there for the onclick doesn't make much sence. I'm assuming you're using a $_GET to see what to include such as: <?php if($_GET['page']=='seniors'){ include ("seniors.php"); }elseif($_GET['page']=='something else'){ include ("somethingelse.php"); } ?> If the above looks familiar to your code you're better of doing it all in php instead of trying to use javascript to change a css class. Using an onclick event would be pointless in that case since the page simply refreshes and undoing the javascript onclick action. You might want to look up what the difference is between clientside and serverside. Hope it helps. Quote Link to comment https://forums.phpfreaks.com/topic/166834-javascript-active-state-change/#findComment-880261 Share on other sites More sharing options...
stevejvan Posted July 22, 2009 Author Share Posted July 22, 2009 You are right, I am using the GET statement you included sorry I said Includes. So could you give me an example of how I could change the position of a <li> image using php? Quote Link to comment https://forums.phpfreaks.com/topic/166834-javascript-active-state-change/#findComment-880367 Share on other sites More sharing options...
RichardRotterdam Posted July 23, 2009 Share Posted July 23, 2009 You are right, I am using the GET statement you included sorry I said Includes. So could you give me an example of how I could change the position of a <li> image using php? <a href="?page=seniors" class="genreseniors" <?php echo(isset($_GET['page'])&& $_GET['page']=='seniors')?'class="highlight"':"" ;?> >link</a> Quote Link to comment https://forums.phpfreaks.com/topic/166834-javascript-active-state-change/#findComment-881055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.