Solved

Change HTML class based on select option value through JavaScript/jQuery

Posted on 2013-01-15
3
478 Views
Last Modified: 2013-01-16
I have a long list of options in a select menu.

<select name="top-menu" id="menu-selector">
	<option value="#">Choose a category</option>
	<option value="ABC">ABC</option>
	<option value="DEF">DEF</option>
	<option value="GHI">GHI</option>
</select>

Open in new window

When an option is selected, jQuery will fade in a new select menu based on the value of that option. In other words, choosing ABC will fade in another select menu where id="ABC". As of right now, I have this.

$(document).ready(function (){
	$("#menu-selector").change(function() {
		document.getElementById($(this).val()).fadeIn('slow');
	});
});

Open in new window

However, that's not working. It throws this error:
Uncaught TypeError: Object #<HTMLSelectElement> has no method 'fadeIn'

Open in new window

How can I fix this?
0
Comment
Question by:vacpartswarehouse
3 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38780962
Try this:
 $("#menu-selector").change(function () {
                $("#" + $(this).val()).fadeIn('slow');
            });

Open in new window

0
 
LVL 3

Expert Comment

by:Khilu
ID: 38781606
 $("#menu-selector").change(function () {
   $(this).fadeIn('slow');
            });

Open in new window

0
 

Author Closing Comment

by:vacpartswarehouse
ID: 38782904
This is perfect! Thank you so much!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question