I have javascript that is trying to validate a form, more specifically the "type=date" part of the form. But for some reason when I submit the form it doesn't even run the script (I think?) and just goes to the page specified in
here is the code
<!-- script to make sure only weekdays are selected -->
<script>
var date = document.querySelector('[type=date]');
function noWeekends(e){
var day = new Date( e.target.value ).getUTCDay();
// Days in JS range from 0-6 where 0 is Sunday and 6 is Saturday
if( day == 0 || day == 6 ){
e.target.setCustomValidity('Please select a weekday.');
return false;
} else {
e.target.setCustomValidity('');
}
}
date.addEventListener('input',noWeekends);
</script>
<!--============================================================
=======================form starts here=========================-->
<form action="confirm_booking.php" onsubmit="noWeekends()" method='post'>
<?php
echo "Room: ";
select_room();
?>
week starting: <input type=date name='WeekStart'/>
<input type="submit" value="Book Room">
</form>