Forum Moderators: open

Message Too Old, No Replies

jQuery to output empty select element

         

dbarasuk

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

10+ Year Member



Hi,
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>';
}
$annee.text($options);

Fotiman

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

WebmasterWorld Senior Member 10+ 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.

dbarasuk

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

10+ Year Member



Thank you so much, it works!