Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-16-2012, 01:24 AM   PM User | #1
ajoros
New Coder

 
Join Date: Jun 2012
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
ajoros is an unknown quantity at this point
Tree submenu, need two independent bold-on-click feature

Hey there,

In my tree menu seen at http://www.wrcc.dri.edu/monitor/WWDT/index.php, is there a way to make the Variable sub menu and Region sub menu independent of eachother in terms of being bold when clicked... So for example, If I click PDSI I want that to become bold and then if I click Arizona I want that to become bold as well. I would like variable and region to both be bold when the user clicks on it. This makes it easier for the user to know what he/she clicked by just looking at the tree menu. Right now, only the active or recently clicked variable/region become bold.

You can view my source code and see that right now I have:

Code:
<script type="text/javascript">
$(function(){
$('#variable').find('a').each(function(){
if (this.href==location.href){
$(this).addClass('Active');
}else{
$(this).removeClass('Active');
}
});
});
</script>

<script type="text/javascript">
$(function(){
$('#region').find('a').each(function(){
if (this.href==location.href){
$(this).addClass('Active');
}else{
$(this).removeClass('Active');
}
});
});
</script>
Thanks for all and any help
ajoros is offline   Reply With Quote
Old 07-16-2012, 07:48 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,306
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
well, since the href changes on every click and the 2 menus only get bolded if the href's match, then using what you have, it's not going to work properly, because the href in one menu isnt going to match the other, so you may need to rethink your overall approach to the problem.

you could parse the current href for the folder= or region= variables, and use that specific info to apply the desired coloring, but with the way you have your backend setup, when they click on a region, it's a new page, when they click on the variable menu, thats a new page and url.

so you might want to rethink the backend a bit?. The url in browser only shows folder= or region=, but the php side is obviously showing the correct info based on those selections
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 07-16-2012, 08:16 PM   PM User | #3
ajoros
New Coder

 
Join Date: Jun 2012
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
ajoros is an unknown quantity at this point
Quote:
you could parse the current href for the folder= or region= variables, and use that specific info to apply the desired coloring
How would I code this up in JavaScript though? Thanks for the input! What would I add/change to the code:

Code:
</script>
<script type="text/javascript">
$(function(){
$('#variable').find('a').each(function(){
if (this.href==location.href){
$(this).addClass('Active');
}else{
$(this).removeClass('Active');
}
});
});
</script>
ajoros is offline   Reply With Quote
Old 07-17-2012, 12:39 AM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,306
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
from http://www.kevinleary.net/get-url-pa...script-jquery/

Code:
// Parse URL Queries Method
(function($){
	$.getQuery = function( query ) {
		query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var expr = "[\\?&]"+query+"=([^&#]*)";
		var regex = new RegExp( expr );
		var results = regex.exec( window.location.href );
		if( results !== null ) {
			return results[1];
			return decodeURIComponent(results[1].replace(/\+/g, " "));
		} else {
			return false;
		}
	};
})(jQuery);
 
// Document load
$(function(){
	var test_query = $.getQuery('test');
	alert(test_query); // For the URL http://www.kevinleary.net/?test=yes, the value would be "yes"
});
you'd do that sort of that thing to parse the values in the url and instead of matching directly against the href you use something like var $region= $.getquery("region"); and compare against the variable $region instead.

if you get the php reworked so the url includes both selections in the url, you'll be straight.

Id like to point out since your doing a page refresh every time anyways, you could do all of this in php and it'd probably be more efficient, but of course it's about whatever works for your needs.
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users

Last edited by DanInMa; 07-17-2012 at 12:53 AM.. Reason: trying to get in the habit of naming jquery object with the $
DanInMa is offline   Reply With Quote
Old 07-17-2012, 03:54 AM   PM User | #5
ajoros
New Coder

 
Join Date: Jun 2012
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
ajoros is an unknown quantity at this point
hetlakoopm4, images are broken.
ajoros is offline   Reply With Quote
Old 07-23-2012, 08:06 AM   PM User | #6
ajoros
New Coder

 
Join Date: Jun 2012
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
ajoros is an unknown quantity at this point
Bump.......... any help? I still cant get this to work...
ajoros is offline   Reply With Quote
Old 07-23-2012, 09:03 AM   PM User | #7
ajoros
New Coder

 
Join Date: Jun 2012
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
ajoros is an unknown quantity at this point
noi, how can i do this in the php ??
ajoros is offline   Reply With Quote
Reply

Bookmarks

Tags
html, java, javascript, jquery

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 05:30 AM.


Advertisement
Log in to turn off these ads.