- Joined
- Oct 24, 2013
- Messages
- 47
- Reaction score
- 0
how to make an input box enable for only past dates and for the startdate that if it falls in the current month in JavaScript.
The input box should be disabled for future dates and for the startdate if it falls in the current month.
I have implemented the function but not sure the following logic will work for every scenario.
The input box should be disabled for future dates and for the startdate if it falls in the current month.
I have implemented the function but not sure the following logic will work for every scenario.
JavaScript:
((new Date(startDate)).getMonth() === new Date().getMonth() || startDate > new Date())
const globalPendingStatusIDL3 = "76070";
const check_IsExternalUser_And_PendingStatusL3 = (statusID = null, startDate = null) => {
return !!statusID && !!startDate ? (statusID === "76070" && ((new Date(startDate)).getMonth() === new Date().getMonth() || startDate > new Date())) : false;
};
//Code where the input box is being created and disabled being set using a loop:
strHTML += "<td width=\"100px\"><input class=\"form-control target-form\" data-recordid=\"" + recordid + "\" data-oldvalue=\"" + actualValue + "\" id=\"txtActualValue_" + recordid + "\" data-prevrecordid=\"" + (prevrecordid == "" ? "" : ("txtActualValue_" + prevrecordid)) + "\" value=\"" + actualValue + "\"" + (globalIsStaff ? "" : (check_IsExternalUser_And_PendingStatusL3(statusID,startDate) === true ? "disabled" : "")) + "/></td>";
//Few scenarios and the desired result:
check_IsExternalUser_And_PendingStatusL3("76070",new Date("2022-12-01")); //The input box should be enable
check_IsExternalUser_And_PendingStatusL3("76070",new Date("2023-01-01")); //The input box should be enable
check_IsExternalUser_And_PendingStatusL3("76070",new Date("2023-06-01")); //The input box should be disable
check_IsExternalUser_And_PendingStatusL3("76070",new Date("2023-06-30")); //The input box should be disable
check_IsExternalUser_And_PendingStatusL3("76070",new Date("2023-07-01")); //The input box should be disable
check_IsExternalUser_And_PendingStatusL3("76070",new Date("2024-01-01")); //The input box should be disable
Last edited: