You just need to define gender
in your code (since your trying to access the value
property of gender
via gender.value
).
Try something like this (I tested and it works, by the way):
$(document).ready(function() {
$('.gendercheck').change(function() {
var selectedRadio = $('.gendercheck:checked'); // this is the "checked" radio button that has the class you're using. using .value would be more of the vanilla JS way, which isn't bad, but if you wanted to do it the jQuery way, just get the val like this --> selectedRadio.val();
if (selectedRadio.val() == 0) {
$('.gendertest').text('m');
} else if (selectedRadio.val() == 1) {
$('.gendertest').text('w');
} else {
$('.gendertest').text('error');
}
});
});
For fun, just wanted to show you an example with fewer lines of code. Basically, print the radio input's value instead of defining the if/else statements.
You'd need to modify your html inputs:
<input type="radio" name="feedback-form-visit-again" id="genderm" class="gendercheck" value="m" required> men
<input type="radio" name="feedback-form-visit-again" id="genderw" class="gendercheck" value="w"> women
$(document).ready(function() {
$('.gendercheck').change(function() {
var selectedRadio = $('.gendercheck:checked'); // the checked radio
$('.gendertest').text( selectedRadio.val() ); // output with the radio input's val
});
});