Question about Javascript Date Dropdown

This is a discussion on Question about Javascript Date Dropdown within the Javascript forums in Programming Languages category; Hello all, I'm currently using the good ole Javascript date dropdown in a page to allow people to select dates for reporting purposes. I modified it slightly. It works great but the year selection starts at the current year and goes forward. I need to be able to populate one year prior in the dropdown as well. I've tried a bunch of different things but haven't quite been able to get it. I'm very novice with Javascript! Can the script below be modified to show what it does now and 1 year prior to the current year? <script type="text/javascript"> var ...

Go Back   Application Development Forum > Programming Languages > Javascript

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 11-27-2008, 09:12 AM
Junior Member
 
Join Date: Nov 2008
Pauley is on a distinguished road
Default Question about Javascript Date Dropdown

Hello all,

I'm currently using the good ole Javascript date dropdown in a page to allow people to select dates for reporting purposes. I modified it slightly. It works great but the year selection starts at the current year and goes forward. I need to be able to populate one year prior in the dropdown as well.

I've tried a bunch of different things but haven't quite been able to get it. I'm very novice with Javascript!

Can the script below be modified to show what it does now and 1 year prior to the current year?

<script type="text/javascript">

var monthtext=['01','02','03','04','05','06','07','08','09','10', '11','12'];

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<32; i++)
dayfield.options[i]=new Option(i, i)
dayfield.options[0]=new Option(today.getDate(), today.getDate(), true, true)
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)

var thisyear=today.getFullYear()
for (var y=0; y<20; y++){
yearfield.options[y]=new Option(thisyear, thisyear)
thisyear+=1
}
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true)
}

Any help would be greatly appreciated!
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 07:43 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.