Andrew R Posted February 14, 2009 Share Posted February 14, 2009 Hello I am using the following script to populate a drop down date input (Day, Month, Year) 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<20; y++){ yearfield.options[y]=new Option(thisyear, thisyear) thisyear+=1 } yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year } There is a problem in that the script displays the current date + 20 years in advance. How would I modify the script to display the current date but also the years before it. Many thanks Link to comment https://forums.phpfreaks.com/topic/145231-drop-down-date-input/ Share on other sites More sharing options...
Mchl Posted February 14, 2009 Share Posted February 14, 2009 Why don't you use some ready datepicker widget? I used to use this one from Frequency Decoder http://www.frequency-decoder.com/demo/date-picker-v4/ Link to comment https://forums.phpfreaks.com/topic/145231-drop-down-date-input/#findComment-762368 Share on other sites More sharing options...
Andrew R Posted February 14, 2009 Author Share Posted February 14, 2009 Why don't you use some ready datepicker widget? I used to use this one from Frequency Decoder http://www.frequency-decoder.com/demo/date-picker-v4/ Thanks for the reply I just wanted to use a lightweight script instead. Link to comment https://forums.phpfreaks.com/topic/145231-drop-down-date-input/#findComment-762388 Share on other sites More sharing options...
Mchl Posted February 14, 2009 Share Posted February 14, 2009 I can't say ca. 100kB is 'heavy weight' And it's really useful. Link to comment https://forums.phpfreaks.com/topic/145231-drop-down-date-input/#findComment-762400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.