I have a problem in IE7. The gen function won’t generate any options for the select.
There’s this select
<select id="year_individ" name="age" onclick="showCategory();">
<option></option>
</select>
that I generate years for (ranging from 1942-1994) this way:
$(document).ready(function() {
var myselect=document.getElementById("year_individ"),
year = new Date(1995);
var gen = function(max){
do {
year--;
myselect.add(new Option(year,max),null);
max++;
} while(max<71);
}(18);
});
function showCategory() {
if ($('.gender').is(':checked')) {
if ($('#year_individ').val() >= 18) {
if ($('#female').is(':checked')) {
$('#category').html('Women ');
} else {
$('#category').html('Men ');
}
age = parseInt($('#year_individ').val());
if (age < 40) $('#category').append('18-39 yrs');
else if (age < 50) $('#category').append('40-49 yrs');
else $('#category').append('50 and more ');
}
else
$('#category').html('set gender and year');
}
}
It’s supposed to change the category when I click on the select. (also ‘gender’ radio has to be checked).
I’m using jQuery 1.5.1 min. It works in chrome, firefox and opera.
here’s the code (it actually doesn’t work in the jsfiddle) http://jsfiddle.net/5DvHj/2/
Thank you
Why do you use inline function ?
And you should use jquery to add option :