Date triple drop-down box (forwarded from network + organized)

Source: Internet
Author: User
Reprinted and sorted out:
 
Code
<Script language = "javascript" type = "text/javascript">
// For birthday


Function YYYYMMDDstart ()
{
MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31];

// Add content to the annual drop-down box first
Var y = new Date (). getFullYear ();
For (var I = (y-100); I <(y + 1); I ++) // take this year as standard, first 30 years, last 30 years
Year. options. add (new Option ("" + I + "year", I ));

// Drop-down box for month assignment
For (var I = 1; I <13; I ++)
Month. options. add (new Option ("" + I + "month", I ));

Year. value = y;
Month. value = new Date (). getMonth () + 1;
Var n = MonHead [new Date (). getMonth ()];
If (new Date (). getMonth () = 1 & IsPinYear (YYYYvalue) n ++;
WriteDay (n); // Date drop-down box
Day. value = new Date (). getDate ();
}

Function YYYYDD (str) // The date when the year changes (mainly to determine the year of the week)
{
Var MMvalue = month. value;
If (MMvalue = "") {var e = day; optionsClear (e); return ;}
Var n = MonHead [MMvalue-1];
Var dayValue = day. value;
If (MMvalue = 2 & IsPinYear (str) n ++;
WriteDay (n );
// If the selected date is within this range, reset the date.
If (dayValue <= n );
Day. value = dayValue;
}
Function MMDD (str) // Date association when the month changes
{
Var YYYYvalue = year. value;
If (YYYYvalue = "") {var e = day; optionsClear (e); return ;}
Var n = MonHead [str-1];
Var dayValue = day. value;
If (str = 2 & IsPinYear (YYYYvalue) n ++;
WriteDay (n );
If (dayValue <= n );
Day. value = dayValue;
}
Function writeDay (n) // drop-down list of write dates based on conditions
{
Var e = day; optionsClear (e );
For (var I = 1; I <(n + 1); I ++)
E. options. add (new Option ("" + I + "", I ));
}
Function IsPinYear (year) // determines whether to renew the year
{
Return (0 = year % 4 & (year % 100! = 0 | year % 400 = 0 ));
}
Function optionsClear (e)
{
E. options. length = 1;
}

</Script>

Html code:

<Td class = "font_R"> birthday </td>
<Td>
<Select id = "ddlYear" runat = "server" onchange = "YYYYDD (this. value)">
<Option value = "" selected = "selected"> select year </option>
</Select>
<Select id = "ddlMonth" runat = "server" onchange = "MMDD (this. value)">
<Option value = "" selected = "selected"> select month </option>
</Select>
<Select id = "ddlDay" runat = "server">
<Option value = "" runat = "server" selected = "selected"> select day </option>
</Select>
</Td>
……
        var year, month, day;
year = document.getElementById('<%=ddlYear.ClientID %>');
month = document.getElementById('<%=ddlMonth.ClientID %>');
day = document.getElementById('<%=ddlDay.ClientID %>');

YYYYMMDDstart();
"<script type='text/javascript' language ='javascript' >"+
"year.value={0};YYYYDD({0});year.value={0};month.value={1};day.value={2}</script>", dt.Year.ToString(), dt.Month.ToString(), dt.Day.ToString());

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.