It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

trouble with 'select'

trouble with 'select'

Postby fengmkex on Mon May 19, 2008 4:59 am

I do not know why this code only display a few years and it goes back all the way to negative years.
I have this in the head:
now = new Date();
year = now.getYear();
and this in the body:
<select>
<option>Year</option>
<script type="text/javascript">
for(i=0 ; i<100 ; i++) {
year = year - i;
document.write("<option>" + year + "</option>");
}
</script>
</select>
I meant for it to display the past hundred years.
Test the script to understand what i mean.
Pls tell me what is the problem. Thanks.
fengmkex
 
Posts: 0
Joined: Sun May 18, 2008 1:47 am

Postby leonard on Mon May 19, 2008 8:30 am

Hi fengmkex

you've got two errors in the script.

1. use the function getFullYear instead of getYear

2. use
Code: Select all
year = year - 1;
instead of
Code: Select all
year = year - i;


note: I'd use node creation and not with write (as you would do in a php-script).

cheers!
- leonard
:%s/^M//
There are 10 kinds of people:
Those who understand binary and those who don't.
User avatar
leonard
100+ Club
 
Posts: 147
Joined: Tue Dec 18, 2007 7:11 am
Location: Switzerland


Who is online

Users browsing this forum: No registered users and 10 guests