Solved

jquery display hidden elements

Posted on 2010-08-22
7
408 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

808 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