| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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! |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.