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]
<Select name = "month" id = "month" onchange = "monthDays (this. value);"> // onchange event
<? Php
For ($ I = 1; $ I <= 12; $ I ++)
{
Echo "<option value =". $ I. "> ";
Echo $ I;
Echo "</option> ";
}
?>
</Select> month
<Select name = "day" id = "day">
<? Php
For ($ I = 1; $ I <= 31; $ I ++)
{
Echo "<option value =". $ I. "> ";
Echo $ I;
Echo "</option> ";
}
?>
</Select> day
<Select name = "month" id = "month" onchange = "monthDays (this. value);"> // onchange event
<? Php
For ($ I = 1; $ I <= 12; $ I ++)
{
Echo "<option value =". $ I. "> ";
Echo $ I;
Echo "</option> ";
}
?>
</Select> month
<Select name = "day" id = "day">
<? Php
For ($ I = 1; $ I <= 31; $ I ++)
{
Echo "<option value =". $ I. "> ";
Echo $ I;
Echo "</option> ";
}
?>
</Select> 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