Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

jQuery to output empty select element



2:11 pm on Sep 23, 2013 (gmt 0)

5+ Year Member

I have a jQuery script designed to output an html select element with decrementing years starting from the current year. Since I'm new to jQuery, can someone help me to find out why my script displays an empty select element?

this is the script:

var $annee = $('Année:&nbsp;<select id="annee"></select>');
var $date = new Date();
var intYear = $date.getFullYear();
var $options = '', i;
for(i = intYear ; i <= 2012; i--){
$options+='<option value="'+i+'">'+i+'</option>';


4:29 pm on Sep 23, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

intYear is initialized to the current year (2013). Your for loop condition checks that i (set to intYear, aka 2013) is LESS THAN or EQUAL TO 2012. Since 2013 is not <= 2012, your loop body never executes.


6:36 am on Sep 24, 2013 (gmt 0)

5+ Year Member

Thank you so much, it works!

Featured Threads

Hot Threads This Week

Hot Threads This Month