homepage Welcome to WebmasterWorld Guest from 54.196.159.11
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
dbarasuk




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

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




msg:4612078
 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.

dbarasuk




msg:4612209
 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