Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 03-13-2009, 02:11 AM Active page script
wildbackpacker's Avatar
Extreme Talker

Posts: 162
Name: Colton
Location: Utah, USA
Trades: 0
On this site I'm redesigning, http://www.graniteschools.org/hs/tay...New/index.html, I need the tabs on the top to be active when you are on the page. As of right now, you have to have <li class="active"> manually for each page. Now I have each page as a template and I can't change it for each page. Is there a script I can use to have the tabs automatically change to active for the current page you're on? Click on 'Departments' and you'll see how the 'Home' tab stays active because the html is the same. Thanks.
__________________
Colton
Wild Backpacker

Please login or register to view this content. Registration is FREE

Last edited by wildbackpacker; 03-13-2009 at 02:17 AM..
wildbackpacker is offline
Reply With Quote
View Public Profile Visit wildbackpacker's homepage!
 
 
Register now for full access!
Old 03-13-2009, 03:01 AM Re: Active page script
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
You can do this with php, which I would recommend.

PHP Code:
<li <?php if ($page == "main") echo 'class="active"'?>>MAIN</a>
<li <?php if ($page == "pages") echo 'class="active"'?>>PAGES</a>
<li <?php if ($page == "other") echo 'class="active"'?>>OTHER</a>
And on the page defining the variable:
PHP Code:
<?php $page "main"?>
- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
stevej is offline
Reply With Quote
View Public Profile
 
Old 03-13-2009, 04:37 AM Re: Active page script
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.modtalk.co.uk/article/dhtml-tabs/
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-13-2009, 11:31 AM Re: Active page script
wildbackpacker's Avatar
Extreme Talker

Posts: 162
Name: Colton
Location: Utah, USA
Trades: 0
Okay thanks stevej, I'll give that a try!
__________________
Colton
Wild Backpacker

Please login or register to view this content. Registration is FREE
wildbackpacker is offline
Reply With Quote
View Public Profile Visit wildbackpacker's homepage!
 
Old 03-13-2009, 05:38 PM Re: Active page script
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
odha:
Before you go chucking about negative rep points maybe you should have looked at the demo page that does exactly what you asked for.
http://www.modtalk.co.uk/_site/code/...ipt/show-hide/
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-13-2009, 05:41 PM Re: Active page script
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
and just to add, you can't actually set the tab "active" using server side code BECAUSE you never go back to the server to get the next "tab" content
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-16-2009, 11:12 AM Re: Active page script
wildbackpacker's Avatar
Extreme Talker

Posts: 162
Name: Colton
Location: Utah, USA
Trades: 0
Hmm. Well I don't quite know how I can implement your Simple Tabs into my site.
__________________
Colton
Wild Backpacker

Please login or register to view this content. Registration is FREE
wildbackpacker is offline
Reply With Quote
View Public Profile Visit wildbackpacker's homepage!
 
Old 03-16-2009, 11:58 AM Re: Active page script
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You don't need to use the entire script and the code. It's just the principles you need.

as you switch tabs you change the classname of the the clicked tab to whatever your active class all the other tabs get set to the default.

For the tabs that open a new URI you simply call the same routine when the page opens to set the appropriate tab.
at the end of the script block you'll see "show('one');" this is "tells" the page which is the "active" tab.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-17-2009, 10:40 PM Re: Active page script
wildbackpacker's Avatar
Extreme Talker

Posts: 162
Name: Colton
Location: Utah, USA
Trades: 0
Well maybe I just don't understand the script then.

I need something that I don't have to modify for each page; it just compares the url you're on to the url the tab is linked to.
__________________
Colton
Wild Backpacker

Please login or register to view this content. Registration is FREE
wildbackpacker is offline
Reply With Quote
View Public Profile Visit wildbackpacker's homepage!
 
Old 03-24-2009, 11:22 AM Re: Active page script
wildbackpacker's Avatar
Extreme Talker

Posts: 162
Name: Colton
Location: Utah, USA
Trades: 0
IF there is a way to do this as you say, that would be great! Otherwise, I might be out of luck. I've search the internet and haven't really found a solution to my problem:

I need a script, my host doesn't support php, that can be the same on every page, and it recognizes which page your on and sets a certain tab to 'active' without me changing the script for each page.

Thanks!
__________________
Colton
Wild Backpacker

Please login or register to view this content. Registration is FREE
wildbackpacker is offline
Reply With Quote
View Public Profile Visit wildbackpacker's homepage!
 
Old 03-24-2009, 01:56 PM Re: Active page script
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
I think there has been a simple misunderstanding here. If you can put this script on every page, it will do the trick:
Code:
<script type=text/javascript">
(function() {
var a = document.getElementById("top_nav").getElementsByTagName("a");
for(var i=0; i<a.length; i++) {
     if(a[i].href == window.location)
               a[i].className = "active";
}
})()
</script>
Now, style the class, "active" in your CSS document, however you like.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-24-2009, 07:10 PM Re: Active page script
wildbackpacker's Avatar
Extreme Talker

Posts: 162
Name: Colton
Location: Utah, USA
Trades: 0
Well I implemented that script, and it didn't work. Thanks though! I've realized that there just isn't a way to do what I want it to do. You can look at the new script for yourself: http://www.graniteschools.org/hs/tay...new/index.html
__________________
Colton
Wild Backpacker

Please login or register to view this content. Registration is FREE
wildbackpacker is offline
Reply With Quote
View Public Profile Visit wildbackpacker's homepage!
 
Old 03-24-2009, 10:24 PM Re: Active page script
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
The script I gave you will do exactly as you requested. What is required is for you to take extra step to actually style the class "active" (on the <a> not the <li>). Be sure to put it at the bottom of the page, where it will actually work.

I don't see anything new about the new "script" you linked to.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 03-24-2009 at 10:27 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-07-2009, 01:24 PM Re: Active page script
wildbackpacker's Avatar
Extreme Talker

Posts: 162
Name: Colton
Location: Utah, USA
Trades: 0
The new script is up there, but I'm not sure how I style the a so that it has the background of the active tab. Also, will this activate the Departments tab even if it is on a page like /New/departments/business/businessindex.html?

Sorry for all the questions and the delayed response. Thanks for your time on this issue!
__________________
Colton
Wild Backpacker

Please login or register to view this content. Registration is FREE
wildbackpacker is offline
Reply With Quote
View Public Profile Visit wildbackpacker's homepage!
 
Reply     « Reply to Active page script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38306 seconds with 12 queries