JS Month day three-level linkage drop-down box date selection code

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<meta charset= "UTF-8"/>
<meta name= "viewport" content= "width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1, User-scalable=no "/>
<title>js three-level linkage drop-down box date selection code </title>

<body>

<form name= "Reg_testdate" >
<select name= "YYYY" onchange= "Yyyydd (this.value)" >
<option value= "" > Please select year </option>
</select>
<select name= "MM" onchange= "MMDD (this.value)" >
<option value= "" > select month </option>
</select>
<select name= "DD" >
<option value= "" > Select Day </option>
</select>
</form>

<script language= "JavaScript" >
function Yyyymmddstart () {
Monhead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
Give the contents of the under Decade frame first
var y = new Date (). getFullYear ();
for (var i = (y-30); i < (y +); i++)//Based on this year, first 30 years, 30 years after
Document.reg_testdate. YYYY.options.add (New Option ("" + i + "year", I));
Assign month drop-down box
for (var i = 1; i <; i++)
Document.reg_testdate. MM.options.add (New Option ("" + i + "month", I));
Document.reg_testdate. Yyyy.value = y;
Document.reg_testdate. Mm.value = new Date (). GetMonth () + 1;
var n = monhead[new Date (). GetMonth ()];
if (new Date (). GetMonth () = = 1 && ispinyear (yyyyvalue)) n++;
Writeday (n); Assign Date drop-down box Author:meizz
Document.reg_testdate. Dd.value = new Date (). GetDate ();
}
if (document.attachevent)
Window.attachevent ("onload", Yyyymmddstart);
Else
Window.addeventlistener (' Load ', Yyyymmddstart, false);

Date changes when function Yyyydd (str)//year changes (mainly judging leap common year)
{
var mmvalue = document.reg_testdate. Mm.options[document.reg_testdate. Mm.selectedindex].value;
if (Mmvalue = = "") {
var e = document.reg_testdate. DD;
Optionsclear (e);
Return
}
var n = monhead[mmvalue-1];
if (Mmvalue = = 2 && ispinyear (str)) n++;
Writeday (N)
}

Date linkage when function MMDD (str)//month is changed
{
var yyyyvalue = document.reg_testdate. Yyyy.options[document.reg_testdate. Yyyy.selectedindex].value;
if (Yyyyvalue = = "") {
var e = document.reg_testdate. DD;
Optionsclear (e);
Return
}
var n = monhead[str-1];
if (str = = 2 && ispinyear (yyyyvalue)) n++;
Writeday (N)
}

function Writeday (n)//drop-down box based on conditional write date
{
var e = document.reg_testdate. DD;
Optionsclear (e);
for (var i = 1; i < (n + 1); i++)
E.options.add (New Option ("" + i + "Day", I));
}

function Ispinyear (year)//Determine if leap common year
{
return (0 = = year% 4 && (year%!! = 0 | | year% 400 = = 0));
}

function Optionsclear (e) {
E.options.length = 1;
}
</script>
</body>

JS Month day three-level linkage drop-down box date selection code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.