View Full Version : Self updating date drop down box

12-20-2006, 05:05 AM
I'm trying to make a drop down box for the date mont and year for my website. However the days in february are 28 or 29 but the other months have either 30 or 31. How can i make a script that enables the date drop down box to change to the appropriate number of days,say if february was selected or if december was selected also considering leaps years and stuff

12-20-2006, 02:00 PM

Start by writing "please" and "thank you."

12-21-2006, 08:26 AM
sorry about that I was rushing to work and a bit frustrated coz I had tried everything I couold think of. I'm really sorry, may you please advise me on how I can go abput solving my problem

Thank you

12-21-2006, 09:23 AM
Try this example for finding the number of days in a month. There may be a better way but I don't know it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<title>Calc Days in Month</title>
<script type="text/javascript">
function doIt(s) {
var adiv = document.getElementById("adiv");
adiv.innerHTML = s;

function calcDays(mon, year) {
var dt = new Date();
var m = parseInt(mon) - 1; // months for Date() are from 0 to 11
var y = parseInt(year);

for (var i = 1; i < 5; i++) {
dt.setFullYear(y, m, 28 + i); // assume each month has at least 28 days
if (dt.getMonth() != m) {

return(28 + i - 1);
<form name="f" action="#" onsubmit="return(false);">
<label>Month <input type="text" name="m" value="12"></label>
<br />
<label>Year <input type="text" name="y" value="2006"></label>
<button onclick="doIt(calcDays(document.f.m.value, document.f.y.value));">Calc Num Days</button>
<br />
<div id="adiv"> </div>