The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
Selecting the date from drop down
Discuss Selecting the date from drop down in the JavaScript Development forum on Dev Shed. Selecting the date from drop down JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 2nd, 2009, 04:38 AM
|
|
Contributing User
|
|
Join Date: Feb 2007
Posts: 174
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
|

February 2nd, 2009, 05:52 AM
|
 |
hack of all trades
|
|
Join Date: Jan 2009
Location: Madrid
|
|
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
}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|