During registration, the number of days of the month changes with the change of the month. this small function is used in many places! & Lt; 5 & gt; change PHP code [php] & lt; selectname & quot; month & quot; id & quot; month & quot; onchange & quot; monthDays (this. val
During registration, the number of days of the month changes with the change of the month. this small function is used in many places!
<5> The number of days of a month changes with the month
PHP code
[Php]
// Onchange event For ($ I = 1; $ I <= 12; $ I ++){Echo"";Echo $ I;Echo"";}?>Month
For ($ I = 1; $ I <= 31; $ I ++){Echo"";Echo $ I;Echo"";}?>Day
// Onchange event For ($ I = 1; $ I <= 12; $ I ++){Echo"";Echo $ I;Echo"";}?>Month
For ($ I = 1; $ I <= 31; $ I ++){Echo"";Echo $ I;Echo"";}?>Day
Js code
[Javascript]
Function monthDays (month)
{
Var xmlhttp;
If (window. XMLHttpRequest)
{// Code for IE7 +, Firefox, Chrome, Opera, Safari
Xmlhttp = new XMLHttpRequest ();
}
Else
{// Code for IE6, IE5
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
If (month = 2)
{
Document. getElementById ("day"). length = 0; // first clear the select option of the number of days of the month
For (I = 1; I <= 29; I ++)
{
Document. getElementById ("day"). options. add (new Option (I, I ));
}
}
Else if (month = 4 | month = 6 | month = 9 | month = 11)
{
Document. getElementById ("day"). length = 0;
For (I = 1; I <= 30; I ++)
{
Document. getElementById ("day"). options. add (new Option (I, I ));
}
}
Else
{
Document. getElementById ("day"). length = 0;
For (I = 1; I <= 31; I ++)
{
Document. getElementById ("day"). options. add (new Option (I, I ));
}
}
}
}
Xmlhttp. open ("GET", "index. php", true );
Xmlhttp. send ();
}
Function monthDays (month)
{
Var xmlhttp;
If (window. XMLHttpRequest)
{// Code for IE7 +, Firefox, Chrome, Opera, Safari
Xmlhttp = new XMLHttpRequest ();
}
Else
{// Code for IE6, IE5
Xmlhttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Xmlhttp. onreadystatechange = function ()
{
If (xmlhttp. readyState = 4 & xmlhttp. status = 200)
{
If (month = 2)
{
Document. getElementById ("day"). length = 0; // first clear the select option of the number of days of the month
For (I = 1; I <= 29; I ++)
{
Document. getElementById ("day"). options. add (new Option (I, I ));
}
}
Else if (month = 4 | month = 6 | month = 9 | month = 11)
{
Document. getElementById ("day"). length = 0;
For (I = 1; I <= 30; I ++)
{
Document. getElementById ("day"). options. add (new Option (I, I ));
}
}
Else
{
Document. getElementById ("day"). length = 0;
For (I = 1; I <= 31; I ++)
{
Document. getElementById ("day"). options. add (new Option (I, I ));
}
}
}
}
Xmlhttp. open ("GET", "index. php", true );
Xmlhttp. send ();
}
This effect still uses the Ajax partial refresh technology. You are welcome to exchange and learn. (To be continued)
From wyzhangchengjin123