Can you please let me know how I can use JavaScript Switch Case in case like below?
<input type="checkbox" name="animal" value="Cat" id="cats" />Cats<br />
<input type="checkbox" name="animal" value="Dog" id="dogs" />Dogs<br />
<input type="checkbox" name="animal" value="Bird" id="birds" />Birds<br />
<script>
$('input:checkbox').change(function () {
if ($(this).is(':checked')) {
if (this.id == "cats") {
alert("Cat Selected");
}
if (this.id == "dogs") {
alert("Dogs Selected");
}
if (this.id == "birds") {
alert("Birds Selected");
}
} else {
alert('Un Checked');
}
});
</script>
I really need to learn how to use the JavaScript Switch Case on a real scenario like this , Thanks.
switchconstruct instead of multipleif?