Home > Forum > Rules, JS, SQL > How to block the possibility of choosing current day while after 9.00 A.M

How to block the possibility of choosing current day while after 9.00 A.M
0

Hello there :)

I have yet another problem, regarding the form validation. I've attached the rules that I've applied.
What I want to do is I want to block the occurence of choosing current day while it's after 9.00 A.M.
Otherwise If the day is <> than Today() then the result is TRUE, which means, you are able to go further.

Best Regards,

Igor

This code checks if the selected date is today and if the current time is after 9:00 A.M., blocking form submission if both conditions are true. Otherwise, it allows the form to be submitted:

function validateForm() {
var selectedDay = document.getElementById('dayField').value;
var today = new Date();
var selectedDate = new Date(selectedDay);

if (selectedDate.toDateString() === today.toDateString()) {
var currentTime = today.getHours();
if (currentTime >= 9) {
alert("You cannot select today after 9:00 A.M.");
return false;
}
}
return true;
}

// Attach this function to your form's onsubmit event
document.getElementById('yourFormId').onsubmit = validateForm;