JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 2nd, 2009, 04:38 AM
runnerjp runnerjp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 174 runnerjp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 13 h 3 m 15 sec
Reputation Power: 7
Selecting the date from drop down

currently i have


Code:
<script type="text/javascript">
var monthtext=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'];

function populatedropdown(dayfield, monthfield, yearfield){
var today=new Date()
var dayfield=document.getElementById(dayfield)
var monthfield=document.getElementById(monthfield)
var yearfield=document.getElementById(yearfield)
for (var i=0; i<31; i++)
dayfield.options[i]=new Option(i, i+1)
dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
for (var m=0; m<12; m++)
monthfield.options[m]=new Option(monthtext[m], monthtext[m])
monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month
var thisyear=today.getFullYear()
for (var y=0; y<80; y++){
yearfield.options[y]=new Option(y, y-1)
thisyear+=1
}
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
}
</script>


but my date field looks liek this

2009
1
2
3
4
5
6
7


i want it to be

2009
2008
2007
2006

ect

Reply With Quote
  #2  
Old February 2nd, 2009, 05:52 AM
haydenchambers's Avatar
haydenchambers haydenchambers is offline
hack of all trades
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2009
Location: Madrid
Posts: 900 haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level)haydenchambers User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Week 23 h 24 m 53 sec
Reputation Power: 516
Send a message via Google Talk to haydenchambers Send a message via Skype to haydenchambers
Code:
function populatedropdown(dayfield, monthfield, yearfield){
	var today=new Date()
	var dayfield=document.getElementById(dayfield)
	var monthfield=document.getElementById(monthfield)
	var yearfield=document.getElementById(yearfield)
	for (var i = 0; i < 31; i++) {
		dayfield.options[i] = new Option(i, i + 1)
	}
	dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
	for (var m = 0; m < 12; m++) {
		monthfield.options[m] = new Option(monthtext[m], monthtext[m])
	}
	monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month
	var thisyear=today.getFullYear()
	var yearindex = 0;
	var numberOfYears = 50;
	for (var y=thisyear; y>(thisyear - numberOfYears); y--) {
		yearfield.options[yearindex]=new Option(y, y);
		yearindex++;
		//thisyear+=1
	}
	yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Selecting the date from drop down

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap