This is the latest version that works.
In the dropdown I have an ID of #service, when the dropdown is selected if the value is PPC then it will do one function, else it will do another function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<script> $(document).ready(function() { $(document).on('change','#service',function() { var dog = $(this).val() if (dog=="PPC") { $("#wordpressquestion").hide(); } else { $("#wordpressquestion").show(); } }); }); //end ready </script> |
The code below is not connected to the above code, its just a another version of the code!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <label>How many cats have you had in the last 5 years?</label> <select name="CallBackTime" id="hidden-form"> <option selected="selected">please select</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> <script> $(document).ready(function() { $('#box1').hide(); $('#box2').hide(); $('#box3').hide(); $('#hidden-form').change(function() { var dog = $(this).val(); // alert('Value change to ' + dog); if (dog == "1") { // alert("hi"); $('#box1').show(); $('#box2').hide(); $('#box3').hide(); } if (dog == "2") { // alert("hi"); $('#box1').show(); $('#box2').show(); $('#box3').hide(); } if (dog == "3") { // alert("hi"); $('#box1').show(); $('#box2').show(); $('#box3').show(); } }); }); //end ready </script> <div id ="box1"> hi1 </div> <div id ="box2"> hi2 </div> <div id ="box3"> hi3 </div> |
Hide textbox on dropdown
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <label>How many cats have you had in the last 5 years?</label> <select name="CallBackTime" id="hidden-form"> <option selected="selected">please select</option> <option value="1">1</option> </select> <script> $(document).ready(function() { $('#hidden-form').change(function() { var dog = $(this).val(); if (dog == "1") { $('#box1').hide(); } }); }); //end ready </script> <div id ="box1"> hi1 </div> |
Another Version
Hide selected option when dropdown is opened