Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jquery display hidden elements

Posted on 2010-08-22
7
409 Views
Last Modified: 2012-05-10
Hello experts

I am trying to do the following. After you select an item under #type-shirts, the next menu option (#types-shirt)is suppose to display (it is set to none on the style sheet), but my code is just not working. Can someone please guide me?

thanks in advance.

html:
      <p id="types-shirts">
            <select>
                  <option value="">Select type shirt</option>
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
            </select>
      </p>
      <p id="types-pants">  //this one has a style: display:none
            <select>
                  <option value="">Select type pants</option>
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
            </select>
      </p>

js:      
            if ($('#types-shirts').val() != ''){
                  $("#types-pants").css("display","block");
            }
0
Comment
Question by:glepiza
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33497836
You may check the option value :

$("#types-shirts").change(function() {
			$("option[value!='']", "#types-shirts").is(":selected")?$("#types-pants").show():$("#types-pants").hide();
		});

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33497837
Test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("#types-shirts").change(function() {
			$("option[value!='']", "#types-shirts").is(":selected")?$("#types-pants").show():$("#types-pants").hide();
		});
	});
</script>
</head>
<body>
<p id="types-shirts">
            <select>
                  <option value="">Select type shirt</option>
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
            </select>
      </p>
      <p id="types-pants" style="display:none">  //this one has a style: display:none
            <select>
                  <option value="">Select type pants</option>
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
            </select>
      </p>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:glepiza
ID: 33497848
oh wow, that was quick. I am learning a lot here, I was looking at so many functions and never saw CHANGE. that is a great one.

Thanks so much.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 82

Expert Comment

by:leakim971
ID: 33497864
0
 

Author Comment

by:glepiza
ID: 33497868
I even understood the logic which is what I like more about this. today is a good learning day.
0
 

Author Comment

by:glepiza
ID: 33497872
thanks a lot for that, I do appreciated. Sometimes I just need someone to guide me. Thanks :)
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33497875
eh eh I understand you! Have fun!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

861 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