I'm trying to get the text below my form to change based on your choice of 2 radio buttons 'yes' or 'no'. I have a function getCats that sets catVal to the chosen radio button. The function showCats features an if statement that changes the text based on the value of catVal. Submit is the id of the submit button for the form and cat is the name of the yes and no radio buttons.
Currently the on click function isn't working, the alert never appears.
$(document).ready(function(){
$('#submit').click(function(){
alert('k');
getCats();
});
});
function getCats() {
var cats = $([name='cat']);
var catVal;
for(var i = 0; i < cats.length; i++){
if(cats[i].checked){
catVal = cats[i].value;
}
}
showCats();
}
function showCats(){
alert('show');
if (catVal == 'yes'){
$("#catReact").text('Hello fellow cat lover!');
}
if (catVal == 'no'){
$("#catReact").text('I guess you must be a dog person.');
}
}