Conditional hiding and showing divs
I have two divs (div1 and div2) which I would like to be shown depending on whether a checkbox is checked and which option is selected from a dropdown box. I currently have this code but it doesn't work very well since if the checkbox is unchecked, the divs are still shown and i don't know how I would fix this: Any help would be fantastic!
- <script>
- $(function() {
- $('#div1').hide();
- $('#div2').hide();
- $('#boxid').change(function() {
- if($('#checkboxid').is(':checked')) {
- if($('#boxid').val() == "TEST1") {
- $("#div1").show();
- $("#div2").hide();
- } else if ($('#boxid').val() == "TEST2") {
- $("#div1").hide();
- $("#div2").show();
- }
- }
- });
- });
- </script>