<Table>
<Tr>
<TD align = "right" width = "120px">
Sales time range:
</TD>
<TD>
<Select id = "ddlchoicedate" name = "ddlchoicedate" runat = "server" onchange = "selectchange (this. Value);">
<Option value = "Select time" selected> select time </option>
<Option value = "today"> today </option>
<Option value = "this week"> this week </option>
<Option value = "this month"> this month </option>
<Option value = "this year"> this year </option>
</SELECT>
</TD>
<TD align = "Left">
<Input type = "text" id = "txtord_createtimestart" runat = "server" width = "85px" onfocus = "datetimestart (this, 'txtord _ createtimeend ');"
Disabled = ""/>
To
<Input type = "text" id = "txtord_createtimeend" runat = "server" width = "85px" onfocus = "datetimeend (this, 'txtord _ createtimestart ');"
Disabled = ""/>
</TD>
</Tr>
</Table>
JS:
<SCRIPT>
// Determine whether the time-end text box is available based on the selection of the drop-down list box in the sales time interval
Function txtdisabled (){
If ($ ("# ddlchoicedate"). Val () = "Select time "){
$ ("# Txtord_createtimestart"). removeattr ("disabled"); // available
$ ("# Txtord_createtimeend"). removeattr ("disabled"); // available
} Else {
$ ("# Txtord_createtimestart"). ATTR ("disabled", "disabled"); // disable
$ ("# Txtord_createtimeend"). ATTR ("disabled", "disabled"); // disable
}
}
$ (Document). Ready (function (){
Txtdisabled ();
});
Function selectchange (selval ){
Txtdisabled ();
Switch (selval ){
Case "Select time ":
$ ("# Txtord_createtimestart"). Val (""); // txtord_createtimestart
$ ("# Txtord_createtimeend"). Val (""); // txtord_createtimeend
Break;
Case "today ":
$ ("# Txtord_createtimestart"). Val (getthisdaytime ("txtord_createtimestart"); // txtord_createtimestart
$ ("# Txtord_createtimeend"). Val (getthisdaytime ("txtord_createtimeend"); // txtord_createtimeend
Break;
Case "this week ":
$ ("# Txtord_createtimestart"). Val (getweektime ("txtord_createtimestart"); // txtord_createtimestart
$ ("# Txtord_createtimeend"). Val (getweektime ("txtord_createtimeend"); // txtord_createtimeend
Break;
Case "this month ":
$ ("# Txtord_createtimestart"). Val (getmonthtime ("txtord_createtimestart"); // txtord_createtimestart
$ ("# Txtord_createtimeend"). Val (getmonthtime ("txtord_createtimeend"); // txtord_createtimeend
Break;
Case "this year ":
$ ("# Txtord_createtimestart"). Val (getyeartime ("txtord_createtimestart"); // txtord_createtimestart
$ ("# Txtord_createtimeend"). Val (getyeartime ("txtord_createtimeend"); // txtord_createtimeend
Break;
Default:
Break;
}
}
VaR now = new date (); // get the current time
VaR year = now. getfullyear (); // get the year
VaR month = now. getmonth () + 1; // get the month // getmonth () is the month starting with 0 // the value of the current month (January 1, = months = 11)
VaR day = now. getdate (); // get the day
VaR gday = now. getday (); // returns the day of the week 0: Sunday 1: Monday 2: Tuesday 3: Wednesday 4: Thursday 5: Friday 6: Saturday
Function getthisdaytime (ID ){
VaR begintime = "";
If (day <10 ){
Begintime = year + "-" + month + "-0" + day; // format y-m-d
} Else {
Begintime = year + "-" + month + "-" + day; // format y-m-d
}
Return begintime;
}
// Calculate the start date of the week and return it in Y-m-D format.
Function getweektime (ID ){
VaR DY = day-gday;
If (gday = 0)
{
Dy-= 7;
}
If (ID = "txtord_createtimeend "){
Dy + = 7;
}
VaR begintime = "";
If (dy <10 ){
Begintime = year + "-" + month + "-0" + dy; // format y-m-d
} Else {
Begintime = year + "-" + month + "-" + dy; // format y-m-d
}
Return begintime;
}
// Calculates the start time of the month and returns the result in Y-m-D format.
Function getmonthtime (ID ){
VaR DY = 1;
If (ID = "txtord_createtimeend "){
DY = solardays (year, month );
}
VaR begintime = "";
If (dy <10 ){
Begintime = year + "-" + month + "-0" + dy; // format y-m-d
} Else {
Begintime = year + "-" + month + "-" + dy; // format y-m-d
}
Return begintime;
}
// Calculate the start time of this year and return it in Y-m-D format
Function getyeartime (ID ){
VaR begintimes = "";
If (ID = "txtord_createtimestart "){
Begintimes = year + "-01-01"; // format: Y-m-d
} Else if (ID = "txtord_createtimeend "){
Begintimes = year + "-12-31"; // format: Y-m-d
}
Return begintimes;
}
// The number of days in the current month
Function solardays (Y, m ){
VaR solarmonth = new array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31 );
If (M = 2)
Return (Y % 4 = 0) & (Y % 100! = 0) | (Y % 400 = 0 ))? 29: 28 );
Else
Return (solarmonth [m-1]);
}
</SCRIPT>
Calculate the start date of the current month and week