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;

Privacy overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognizing you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.


To see a full list of the cookies we use and learn more about their purposes, visit our Privacy Policy.