Drop Down List Show and Hide using jQuery

Drop Down List Show and Hide using jQuery


This is a very simple example of how you are able to use jQuery to show and hide text/div.
The structure is very simple to follow, i am asking if an item exists and if the user selects "Yes" then there is a follow up question. Otherwise, the follow up question remains hidden, also the default selection in drop down is left blank. Great way to set up a questionare/survey.
The example below is how the example should work:

Drop Down List Test

Does this item Exist?

Where?

And here is the code:

 <h1>Drop Down List Test</h1>

<form>
Does this item Exist?<br>
<select id="question">
 <option value="" style="display:none;"></option>
 <option value="Yes">Yes</option>
 <option value="No">No</option>
 <option value="Unsure">Unsure</option>
</select>
<br>
<div id="followUpQuestion">Where? <br><input name="where">
</div>
</form>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>  <script>
 $(document).ready(function() {
  $("#followUpQuestion").hide();
  $("#question").change(function() {
  if($("#question").val() == "Yes"){
  $("#followUpQuestion").show();
  }
  else{
   $("#followUpQuestion").hide();
   }
    
  });
  });

 </script>

Comments

  1. You already feel unsure of yourself, and then you see your worst fears in print. It really knocked me - which is why, I think, I was working, working, working, because I was trying to run away from the fact that I thought I couldn't do it. See the link below for more info.


    #unsure
    www.ufgop.org

    ReplyDelete

Post a Comment

Popular posts from this blog

CS3150 Assignment 1

CS4500 Test 4 Study Guide

CS4150 Assignment 2