- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 12:21 PM
I have a client asking to validate a proposed date field in catalog form that is either the 1st or 16th day of a future month. For example, in onSubmit script, if I submit a form today, the next acceptable proposed date will be April 1st or 16th or May, June, July, or later on. How can I validate if the user picks either the 1st or 16th day of the future month? I am not very good at script calculating on the date. Can anyone help me with this, or do you have a similar code sample?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:29 PM
Please try below code in onsubmit client script, just replace correct field names in code:
function onSubmit() {
// Get the proposed date from the form
var proposedDate = g_form.getValue('proposed_date_field'); // Replace 'proposed_date_field' with the actual field name of the proposed date
// Parse the proposed date to a JavaScript Date object
var proposedDateObj = new Date(proposedDate);
var currentDate = new Date();
// Check if the proposed date is in the future
if (proposedDateObj > currentDate) {
// Check if the proposed date is the 1st or 16th day of the month
var dayOfMonth = proposedDateObj.getDate();
if (dayOfMonth === 1 || dayOfMonth === 16) {
// Proceed with form submission
return true;
} else {
// Display error message and prevent form submission
alert('Please select either the 1st or 16th day of a future month.');
return false;
}
} else {
// Display error message and prevent form submission
alert('Please select a future date.');
return false;
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 06:46 PM
Hi @bbf35621 the below code works for me
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 08:29 PM
Please try below code in onsubmit client script, just replace correct field names in code:
function onSubmit() {
// Get the proposed date from the form
var proposedDate = g_form.getValue('proposed_date_field'); // Replace 'proposed_date_field' with the actual field name of the proposed date
// Parse the proposed date to a JavaScript Date object
var proposedDateObj = new Date(proposedDate);
var currentDate = new Date();
// Check if the proposed date is in the future
if (proposedDateObj > currentDate) {
// Check if the proposed date is the 1st or 16th day of the month
var dayOfMonth = proposedDateObj.getDate();
if (dayOfMonth === 1 || dayOfMonth === 16) {
// Proceed with form submission
return true;
} else {
// Display error message and prevent form submission
alert('Please select either the 1st or 16th day of a future month.');
return false;
}
} else {
// Display error message and prevent form submission
alert('Please select a future date.');
return false;
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks