You are viewing limited content. For full access, please sign in.

Question

Question

Case Statement Help

asked on June 19, 2018

I have a case statement that is not working properly and I could use some eyes to see if anyone can see what I'm not!

 

Here is what I have:

 

/*this seciont shows and hides Tompkins County Responsible fields and Other County fields */
$(document).ready(function () {
       $('.othercounty').hide();  
      $('.SectionShow').hide();
      $('.Submit').hide();
      
$('.occurrencecounty select').on ('change', function(){
    var county = $(this).val();
    switch (county){
      case "Tompkins County":
          $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
                
             } else
             {
               if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
               }}
    });
        break;
      case "Bronx County":
        $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
                
             } else
             {
               if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').show();
                $('.SectionShow').hide();
                $('.Submit').hide();
               }}
    });
        break;
      case "Kings County (Brooklyn)":
        $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
             } else
             {
                if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').show();
                $('.SectionShow').hide();
                $('.Submit').hide();
               }
             }
    });
        break;
      case "New York County (Manhattan)":
        $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
             } else
             {
                if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').show();
                $('.SectionShow').hide();
                $('.Submit').hide();
               }
             }
    });
        break;
      case "Queens County":
        $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
             } else
             {
                if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').show();
                $('.SectionShow').hide();
                $('.Submit').hide();
               }
             }
    });
        break;
      case "Richmond County (Staten Island)":
        $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
             } else
             {
                if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').show();
                $('.SectionShow').hide();
                $('.Submit').hide();
               }
             }
    });
        break;
      case "Not New York State County":
        $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('.SectionShow').show();
                $('.Submit').show();
             } else
             {
                if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').show();
                $('.SectionShow').hide();
                $('.Submit').hide();
               }
             }
    });
        break;
      default:
        $('.tompkinsresidentyn').click(function(){
          if ($('input[value= "Yes"]').is(':checked')){
                $('.othercounty').hide();
                $('#q194').show();
                $('.SectionShow').show();
                $('.Submit').hide();
             } else
             {
                if ($('input[value= "No"]').is(':checked')){
                $('.othercounty').show();
                $('.SectionShow').hide();
                $('.Submit').hide();
               }
             }
        
        });
        
          
    }
              
    });  
  });

It never shows my .othercounty fields. :-(

It used to work.  I'm not sure what I did that made it stop working.

0 0

Replies

replied on June 19, 2018

That is quite a bit of site specific code there. Generally, the first thing I would do is comment out all but one case and check your results. Then add in one case at a time. Hopefully you can isolate which is the problem child. You may have a conflict of fields, but you would be familiar and better to to identify. 

Good luck! 

0 0
replied on June 20, 2018 Show version history

OK.  So I've simplified the script but it still isn't working properly.

$(document).ready(function () {
 $('.othercounty').hide();
 $('.SectionShow').hide();

  $('.occurrencecounty select').on ('change', function(){
  var county = $(this).val();
    switch (county){
    case "Bronx County":
    case "Kings County (Brooklyn)":
    case "New York County (Manhattan)":
    case "Queens County":
    case "Richmond County (Staten Island)":
        $('.tompkinsresidentyn').click(function(){
          if($('input[value= "Yes"]').is(':checked')){
              $('.othercounty').hide();
              $('.SectionShow').show();  
          }
          else 
          if($('input[value= "No"]').is(':checked')){
            $('.othercounty').show();
             $('.SectionShow').hide();
          
        }
                                       
        });
        break;
      default:
        $('.othercounty').show();
         $('.SectionShow').hide();

    }
  
  });
  
});

When I select any of the above in the drop down list, it doesn't matter if I select Yes or No for the .tompkinscountyresidentyn, I get the same results. The default seems to be working though.  Sigh.

0 0
replied on June 20, 2018 Show version history

Are you also hiding .othercounty using Field Rules? Make sure you are not.

Also, try adding 'input' after the class:

$('.othercounty input').show();

What type of field(s) is .othercounty?

If you have another way to confirm you are selecting what you think you should be, that is a good test. For instance, try adding a class to .othercounty that changes the background - just to confirm your selector is correct. Once you have confirmed, you can mark that off the list of troubleshooting.

0 0
replied on June 20, 2018

.othercounty is a class that has two different types of fields.  One is a multi-line that is read only, one is actually and html field.

0 0
replied on June 20, 2018

Can you inspect the element for .othercounty and show it here?

0 0
replied on June 20, 2018

I could, but I think that my problem is here:

$('.tompkinsresidentyn').click(function(){ 
    if($('input[value="Yes"]').is(':checked'))
    	{
          	$('.othercounty').hide();
          	$('.SectionShow').show();  
          }
          else if($('input[value="No"]').is(':checked'))
        {
            $('.othercounty').show();
 			$('.SectionShow').hide();
        }
   });
  

0 0
replied on June 20, 2018

Your logic looks fine to me. I think there is something else going on that isn't here in this code.  Have you confirmed that the .tompiksresidentyn is working correctly? You could do that by monitoring the console with this:

$('.tompkinsresidentyn').click(function(){
console.log('resident yn clicked'); 
    if($('input[value="Yes"]').is(':checked'))
    	{
console.log('yes checked');
//          	$('.othercounty').hide();
//          	$('.SectionShow').show();  
          }
          else if($('input[value="No"]').is(':checked'))
        {
console.log('no checked');
//            $('.othercounty').show();
// 			$('.SectionShow').hide();
        }
   });

Also, confirm that the values in the field for tompiksresidentyn have the values 'Yes' & 'No' defined as its values.

0 0
replied on June 20, 2018

So, I had another form in the same process that was working so I copied it and modified it a little and it is working on the new form. Same code, but it works so I'm not going to complain.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.