homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

jQuery to output empty select element

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

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)

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)

Thank you so much, it works!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved