Switch Statement: Values 0,1 work - "Yes","No" don't

Showing/hiding a div (“#HIDEIFNO”) based on which radio button is checked.
If the possible values coming from teh buttons are “0” or '1", the below works great:


	$(function(){
		$("#inc_tc_cov").change(function () {
			var val = $(this).val();
			switch(parseInt(val)){
			case 1:
				$("#HIDEIFNO").show();
				break;
                        case 0:
				$("#HIDEIFNO").hide();
				break;
			default:	
			    $("#HIDEIFNO").hide();
			}
		});
	});

However, if I change the possible values to “Yes” or “No”, I can’t get it to work.
Code should be the same, just “Yes” or “No” instead of 0 or 1, yes?

	$(function(){
		$("#inc_tc_cov").change(function () {
			var val = $(this).val();
			switch(parseInt(val)){
			case "Yes":
				$("#HIDEIFNO").show();
				break;
                       case "No":
				$("#HIDEIFNO").hide();
				break;
			default:	
			    $("#HIDEIFNO").hide();
			}
		});
	});

Case matches the radio button values.
Tried single quotes as well.

What does this poor idiot have wrong?

What is the value of the switch parameter parseInt(val)?

parseInt converts to base 10 so the result will always be a number and never “Yes” or “No”…

You should never use parseInt without the second parameter anyway - the second parameter should be a number between 2 and 9 or 11 and 36 to indicate what base the supposed number being passed as the first parameter is in that you want to have converted to base 10.

10 is feeling left out :frowning:

Well it has its own Number() function and so doesn’t need to share a function with the others.

Duh “switch(parseInt(val))” - integer and all. Got that part.

OK, if I wanted to check NOT integer values - back to “yes” or “no”, or “pink” and “green” for that matter … what would I need to change?

Just remove the parseInt()