Accountability Posted October 18, 2017 Report Share Posted October 18, 2017 I am trying to make sure the time in entered is less than the time out entered. I was determined to figure this out on my own but just can get go any further without help. Here is my code. Since Defined_Date_Out is required, I thought replacing the users erroneous entry with null would prevent the submission from being initiated. Thanks for any advise ? <div id="datefix"> <script> function DateCheck() { var dateout = document.getElementById('Defined_Time_Out').value; var datein = document.getElementById('Defined_Time_In').value; if (dateout <= datein) alert("Please enter a date and time OUT after date and time IN "); document.getElementById("InsertRecordDefined_Time_Out").value = null; } document.getElementById('InsertRecordDefined_Time_Out').onChange = DateCheck; </script> </div> Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted October 19, 2017 Report Share Posted October 19, 2017 Hello Accountability, I would suggest using following code if you prefer to restrict form submission if the condition "dateout <= datein" is met: <div id="datefix"> <script> function DateCheck() { var dateout = document.getElementById('InsertRecordDefined_Time_Out').value; var datein = document.getElementById('InsertRecordDefined_Time_In').value; if (dateout <= datein) alert("Please enter a date and time OUT after date and time IN "); document.getElementById("InsertRecordDefined_Time_Out").value = null; return false; } document.getElementById('InsertRecordDefined_Time_Out').onChange = DateCheck; </script> </div> Hope this helps. Quote Link to comment Share on other sites More sharing options...
Accountability Posted October 19, 2017 Author Report Share Posted October 19, 2017 Thank you so much for responding. Unfortunately it didn't work. I don't know if this makes a difference but there are two other working scripts right above it https://forums.caspio.com/topic/7022-time-sheet-date-and-time-in-and-out/ Any more advise would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Accountability Posted October 20, 2017 Author Report Share Posted October 20, 2017 Also unsuccessfully tried this: <div id="datefix"> <script> function DateCheck() { var dateout = document.getElementById('InsertRecordDefined_Time_Out').value; var datein = document.getElementById('InsertRecordDefined_Time_In').value; var zero = "00/00/0000" if (dateout <= datein) alert("Please enter a date and time OUT after date and time IN "); document.getElementById("InsertRecordDefined_Time_Out").value = "zero"; return false; } document.getElementById('InsertRecordDefined_Time_Out').onChange = DateCheck; </script> </div> Any suggestions would be greatly appreciated. Thanks in Advance. ! Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted October 23, 2017 Report Share Posted October 23, 2017 Hi Accountability, Try the following code: <div id="datefix"> <script> function DateCheck() { var dateout = document.getElementById('InsertRecordDefined_Time_Out').value; var datein = document.getElementById('InsertRecordDefined_Time_In').value; if (dateout <= datein) alert("Please enter a date and time OUT after date and time IN "); document.getElementById("InsertRecordDefined_Time_Out").value = null; return false; } document.getElementById('InsertRecordDefined_Time_Out').onchange = DateCheck; </script> </div> I have corrected some minor syntax errors. Hope this helps. Quote Link to comment Share on other sites More sharing options...
Accountability Posted October 23, 2017 Author Report Share Posted October 23, 2017 Hello Vitalikssssss, Thanks again for responding. Unfortunately, this does not work. It is really strange because it is such a simple script and with the limited knowledge I have in regards to Javascript, it appears to be flawless. I am really scratching my head on this one. Thanks again. Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted October 24, 2017 Report Share Posted October 24, 2017 15 hours ago, Accountability said: Hello Vitalikssssss, Thanks again for responding. Unfortunately, this does not work. It is really strange because it is such a simple script and with the limited knowledge I have in regards to Javascript, it appears to be flawless. I am really scratching my head on this one. Thanks again. Hi Accountability, Have you put this part in a Header of the Datapage? <div id="datefix"> Can you send me a screenshot from your browser console? Perhaps we`ll be able to trace an error from there. Regards, vitalikssssss Quote Link to comment Share on other sites More sharing options...
douvega Posted October 24, 2017 Report Share Posted October 24, 2017 Hi there, I just tested this code and it works on form submit. Just remember that this Caspio Form should be the only one deployed in your webpage. <script> document.getElementById("caspioform").onsubmit = function(){ var dateOutString = document.getElementById('InsertRecordDefined_Time_Out'); var dateInString = document.getElementById('InsertRecordDefined_Time_In'); var dateOut = new Date(dateOutString.value).getTime(); var dateIn = new Date(dateInString.value).getTime(); if (dateOut <= dateIn){ alert("Please enter a date and time OUT after date and time IN "); dateOutString.value = ''; document.getElementById("cbParamVirtual6").value = ""; document.getElementById("cbParamVirtual7").selectedIndex = ""; document.getElementById("cbParamVirtual8").selectedIndex = ""; document.getElementById("cbParamVirtual10").selectedIndex = ""; return false; } }; </script> Accountability 1 Quote Link to comment Share on other sites More sharing options...
Accountability Posted October 24, 2017 Author Report Share Posted October 24, 2017 Hello Douvega, Many Many Thanks. You are incredible, worked perfectly. THANK YOU, THANK YOU, THANK YOU... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.