Solved

jquery display hidden elements

Posted on 2010-08-22
7
407 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now