473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to create a drop down date menu within a login page

I want to create a drop down menu of month:, day:, and year. The difficulty with this one is that i dont know whether to make this a dynamic menu list - after all - the number of days within the day selection list depends on the month entered and also the year (in the case of a leap year)

So, can any one suggest me with this or can give a sample code..

Thanx
Mar 31 '08 #1
2 6057
I want to create a drop down menu of month:, day:, and year. The difficulty with this one is that i dont know whether to make this a dynamic menu list - after all - the number of days within the day selection list depends on the month entered and also the year (in the case of a leap year)

So, can any one suggest me with this or can give a sample code..

Thanx
hi check out the code below... you will get drop down box with current month and year and the days for the particular month.

I have used 2 functions in the code .One for checking the leap year and other for populating the drop down box on body load.

Read the functions in the code and write a new function if you want to change day if users changes month or year.

And move this post to javascript forum

[html]
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>


<script>
//to check leap year
function checkleapyear(datea)
{
datea = parseInt(datea);

if(datea%4 == 0)
{
if(datea%100 != 0)
{
return true;
}
else
{
if(datea%400 == 0)
return true;
else
return false;
}
}
return false;
}
//to populate drop drow boxex with the current month and date
function populateYearSelect()
{
d = new Date();
curr_year = d.getFullYear();
curr_month=d.getMonth();

document.getElementById('month').options[curr_month].selected=true;
for(i = 0; i < 3; i++)
{
document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i);
}


if(curr_month==0 || curr_month==2 ||curr_month==4 || curr_month==6 || curr_month==7 || curr_month==9 || curr_month===11)
{
for(i=0;i<=30;i++)

document.getElementById('day').options[i] = new Option(i+1,i+1);

}

else if(curr_month==3 || curr_month==5 ||curr_month==8 || curr_month==10)
{
for(i=0;i<=29;i++)

document.getElementById('day').options[i] = new Option(i+1,i+1);


}

if(curr_month==1)
{
var year=document.getElementById('year').value;


if(checkleapyear(year))
{ for(i=0;i<=28;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1); }
else
{ for(i=0;i<=27;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1);}

}

}



</script>

<body onLoad="populateYearSelect()">


<select name="year" id="year" >
</select>

<select name="month" id="month">
<option value=01>JAN</option>
<option value=02>FEB</option>
<option value=03>MAR</option>
<option value=04>APR</option>
<option value=05>MAY</option>
<option value=06>JUN</option>
<option value=07>JUL</option>
<option value=08>AUG</option>
<option value=09>SEP</option>
<option value=10>OCT</option>
<option value=11>NOV</option>
<option value=12>DEC</option>
</select>

<select name="day" id="day">
</select>

</body>



</html>

[/html]
Mar 31 '08 #2
I want to create a drop down menu of month:, day:, and year. The difficulty with this one is that i dont know whether to make this a dynamic menu list - after all - the number of days within the day selection list depends on the month entered and also the year (in the case of a leap year)

So, can any one suggest me with this or can give a sample code..

Thanx
The code below will give you drop down boxes populated with current month and year.
If you want to change the day if user change month or year then write one more function using the same functions that i have used below.

[html]
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>


<script>
//to check leap year
function checkleapyear(datea)
{
datea = parseInt(datea);

if(datea%4 == 0)
{
if(datea%100 != 0)
{
return true;
}
else
{
if(datea%400 == 0)
return true;
else
return false;
}
}
return false;
}
//to populate drop drow boxex with the current month and date
function populateYearSelect()
{
d = new Date();
curr_year = d.getFullYear();
curr_month=d.getMonth();

document.getElementById('month').options[curr_month].selected=true;
for(i = 0; i < 3; i++)
{
document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i);
}


if(curr_month==0 || curr_month==2 ||curr_month==4 || curr_month==6 || curr_month==7 || curr_month==9 || curr_month===11)
{
for(i=0;i<=30;i++)

document.getElementById('day').options[i] = new Option(i+1,i+1);

}

else if(curr_month==3 || curr_month==5 ||curr_month==8 || curr_month==10)
{
for(i=0;i<=29;i++)

document.getElementById('day').options[i] = new Option(i+1,i+1);


}

if(curr_month==1)
{
var year=document.getElementById('year').value;


if(checkleapyear(year))
{ for(i=0;i<=28;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1); }
else
{ for(i=0;i<=27;i++)
document.getElementById('day').options[i] = new Option(i+1,i+1);}

}

}



</script>

<body onLoad="populateYearSelect()">


<select name="year" id="year" >
</select>

<select name="month" id="month">
<option value=01>JAN</option>
<option value=02>FEB</option>
<option value=03>MAR</option>
<option value=04>APR</option>
<option value=05>MAY</option>
<option value=06>JUN</option>
<option value=07>JUL</option>
<option value=08>AUG</option>
<option value=09>SEP</option>
<option value=10>OCT</option>
<option value=11>NOV</option>
<option value=12>DEC</option>
</select>

<select name="day" id="day">
</select>

</body>



</html>

[/html]
Mar 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ngoc | last post by:
Hi I want to build dropdown navigation menu. Searching from google gives many commercial programs -> Not easy to choose. And I want to make it myself. Are there any good tutorials to build...
3
by: dshan | last post by:
Hi all, I can't find an answer to my quesiton anywhere. Given a drop-down list with USA states and other text fields I pass this information for further processing via PHP. If any of the...
3
by: dshan | last post by:
Hi all, I can't find an answer to my quesiton anywhere. Given a drop-down list with USA states and other text fields I pass this information for further processing via PHP. If any of the...
1
by: kevin | last post by:
I was wondering using only javascript i am trying to figure this out. Lets say i have a drop down menu with the following items in it\ <form id='frmitems' name='frmitems' method='post'...
1
gurusarentus
by: gurusarentus | last post by:
I have a web page that is using drop down menu selections to allow students to make a 4 year academic plan online. My problem is not with the menus themselves, but I would like for another field to...
1
by: rich2912 | last post by:
I have a page, with three drop down boxes. Each has four choices linked to a database. Here is what I would like to do: I would like the results of the three choices, to be displayed on the...
2
by: Steve Richter | last post by:
I would like to have a standard site navigation menu, horizontal across the page, at the top of the page. When I hover over a top level menu item I want a drop down menu to appear with the same...
4
by: Buzby | last post by:
I want a drop down date selection box on a form in the format of Mon 18 June 2007, that will go say 400 days in advance from the current date. Can anyone point me in the right direction as I...
4
by: tburger | last post by:
Hey everyone- This is my first post at The Scripts, but I've used the forums before for other programming issues. Hopefully, someone has some solid styling advice for me. I've now been dealing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.