I have created 2 select boxes and want to display the appropriate div when each select box is occupied, so when age is selected a check is done to make sure gender has been selected before running the validate function which gets passed the gender and age values. My problem is however that when female gets passed it seems to be read as male but I cant understand why. Can anyone advise how I can resolve this?
Fiddle: http://jsfiddle.net/Nyh89/2/
JS
var genderList = $('#gender'),
ageList = $('#age'),
gender,
age;
genderList.on('change', function () {
gender = $(this).find(":selected").data('gender');
if (ageList.val()) {
console.log(gender);
validate(age, gender);
}
});
ageList.on('change', function () {
age = $(this).find(":selected").data('year');
if (genderList.val()) {
console.log(gender);
validate(age, gender);
}
});
function validate(age, gender) {
var gen = gender;
if (age <= 1996) {
$('.' + gen + '-under-twelve').show();
} else if (age >= 1997 && age <= 2002) {
$('.' + gen + '-mid').show();
} else {
$('.' + gen + '-over-sixteen').show();
}
}