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

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 05-21-2012, 10:21 PM   PM User | #1
mmchu
New to the CF scene

 
Join Date: May 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mmchu is an unknown quantity at this point
Question Dropdown (return current value)

Hi, i need some help with this if is possible.

I make this dropdown:
Code:
<dl class="dropdown">
<dt><a><span>Select a Field</span></a></dt>
<dd>
<ul id="menu-tags-menu" class="menu">
<li id="menu-item-159" class="menu-item current-menu-item"><a href="http://myweb.com.ar/portfolio/">All Fields</a></li>
<li id="menu-item-54" class="menu-item"><a href="http://myweb.com.ar/tag/branding/">Branding</a></li>
<li id="menu-item-55" class="menu-item"><a href="http://myweb.com.ar/tag/print-design/">Print Design</a></li>
<li id="menu-item-57" class="menu-item"><a href="http://myweb.com.ar/tag/web-design/">Web Design</a></li>
<li id="menu-item-56" class="menu-item"><a href="http://myweb.com.ar/tag/ui-design/">UI Design</a></li>
<li id="menu-item-52" class="menu-item"><a href="http://myweb.com.ar/tag/motion-graphics/">Motion Graphics</a></li>
<li id="menu-item-53" class="menu-item"><a href="http://myweb.com.ar/tag/illustration/">Illustration</a></li>
</ul>
</dd>
</dl>
Working with jquery and this code:
Code:
$(document).ready(function() {
	$(".dropdown dt a").click(function() {
		$(".dropdown dd ul").toggle();
	});
	$(".dropdown dd ul li a").click(function() {
		var text = $(this).html();
		$(".dropdown dt a span").html(text);
		$(".dropdown dd ul").hide();
		$("#result").html("Selected value is: " + getSelectedValue("sample"));
	});
	function getSelectedValue(id) {
		return $("#" + id).find("dt a span.value").html();
	}
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
		$(".dropdown dd ul").hide();
	});
});
This works very well.. but i need the dt a span show me the value of the current li (<li class="current-menu-item">), so instead "Select a Field" must say "All Fields" (current value in this example), and when i go to "Motion Graphics" (for example), when page is load must say "Motion Graphics".

Can i do this adding a variable to take the value of current li and droping when document.ready?

Thanks
mmchu is offline   Reply With Quote
Old 05-21-2012, 11:36 PM   PM User | #2
mmchu
New to the CF scene

 
Join Date: May 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mmchu is an unknown quantity at this point
Here you can see how it works:
http://www.patricioherrera.com.ar/portfolio

Any ideas?
mmchu is offline   Reply With Quote
Reply

Bookmarks

Tags
current, dropdown, return, variable

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 11:04 AM.


Advertisement
Log in to turn off these ads.