This should be an easy fix. In the onsubmit method of your form tag, do the following:
<form onsumbit="return show_alert();">
Instead
<form onsumbit="show_alert();">
Without the return part, a script is run and the form will be submitted anyway. Also, if there is an error condition in the script, you need to add return false; otherwise, the form will still be submitted, and return true; if there is no error. You can edit the script like this:
<script type = "text/javascript"> function show_alert() { if (document.getElementById('time1').value == document.getElementById('time2').value) { alert("ERROR! You cannot book the same timing twice!"); return false; } else if (document.getElementById('time1').value == document.getElementById('time3').value) { alert("ERROR! You cannot book the same timing twice!"); return false; } else if (document.getElementById('time1').value == document.getElementById('time4').value) { alert("ERROR! You cannot book the same timing twice!"); return false; } else if (document.getElementById('time1').value == "0") { alert("ERROR! You cannot leave the first time slot blank!"); return false; } else { return true; } } </script>
source share