lmooring Posted July 22, 2014 Report Share Posted July 22, 2014 I have a need to compare two dates prior to a form being submitted but am not sure how to address this. For example, start and end dates. Rule 1 would be that the start date can not be less than todays date. Rule 2 would be that the end date can not be less than the start date or conversly start date can not be greater then end date. Any assistance would be appreciated. Quote Link to comment Share on other sites More sharing options...
1 Jan Posted July 24, 2014 Report Share Posted July 24, 2014 Hello Liz, I think, you can add the Header&Footer element and try to enter the following code to the Footer: <SCRIPT LANGUAGE="JavaScript"> function checkStart() { var v_sDate = document.getElementById("InsertRecordfirst").value; var v_eDate = document.getElementById("InsertRecordsecond").value; var sDate = new Date(v_sDate); var eDate = new Date(v_eDate); var nDate = new Date(); nDate = Date.now(); var setToday = sDate.getDate() + 1; sDate.setDate(setToday); setToday = eDate.getDate() + 1; eDate.setDate(setToday); if (sDate<nDate) { alert("Start Date should be more than Today"); return false; } else { if (eDate<sDate) { alert("Finish Date should be more than Start Date"); return false; } } } document.getElementById("caspioform").onsubmit=checkStart; </SCRIPT> Please change InsertRecordfirst and InsertRecordsecond to your names of fields. Of course, you can enter your text in alerts. I hope it helps. Quote Link to comment Share on other sites More sharing options...
0 lmooring Posted August 7, 2014 Author Report Share Posted August 7, 2014 Thank you so much for the response. I have tried this in my existing submission form and it does not appear to be working. I am not able to get an error message either so I do not know where the problem lies. I created a test page and table to see if some existing code may be affecting this but I am still not able to get this to work? My test page simply has a start date/ end date and a name text field. I changed the name to the paramater name in front of InsertRecord in the code and placed in the footer of the page. Is there something else I may be missing that I did not update correctly? <SCRIPT LANGUAGE="JavaScript"> function checkStart() { var v_sDate = document.getElementById("InsertRecordSTART_DATE").value; var v_eDate = document.getElementById("InsertRecordEND_DATE").value; var sDate = new Date(v_sDate); var eDate = new Date(v_eDate); var nDate = new Date(); nDate = Date.now(); var setToday = sDate.getDate() + 1; sDate.setDate(setToday); setToday = eDate.getDate() + 1; eDate.setDate(setToday); if (sDate<nDate) { alert("Start Date should be more than Today"); return false; } else { if (eDate<sDate) { alert("Finish Date should be more than Start Date"); return false; } } } document.getElementById("caspioform").onsubmit=checkStart; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
0 Jan Posted August 12, 2014 Report Share Posted August 12, 2014 Hello Liz, Maybe, the capitalization is the problem. Is the name of your field "START_DATE" or "start_date"? Quote Link to comment Share on other sites More sharing options...
0 lmooring Posted August 12, 2014 Author Report Share Posted August 12, 2014 Hi Jan, I double checked and yes I have them in my table in all caps. Is this a problem? Quote Link to comment Share on other sites More sharing options...
0 Jan Posted August 13, 2014 Report Share Posted August 13, 2014 Hi Liz, caps is not a problem, problem might be if capitalization of the name of the field and the name of the variable are different. I have read your code, maybe, the problem in the paragraph before "Today". In your code: if (sDate<nDate) { alert("Start Date should be more than Today"); return false; } Try to put "Today" on the one line: if (sDate<nDate) { alert("Start Date should be more than Today"); return false; } I hope it helps. Quote Link to comment Share on other sites More sharing options...
0 lmooring Posted August 13, 2014 Author Report Share Posted August 13, 2014 Hi Jan, This worked wonderfully! Thank you so much for your help on this! Quote Link to comment Share on other sites More sharing options...
Question
lmooring
I have a need to compare two dates prior to a form being submitted but am not sure how to address this.
For example, start and end dates.
Rule 1 would be that the start date can not be less than todays date.
Rule 2 would be that the end date can not be less than the start date or conversly start date can not be greater then end date.
Any assistance would be appreciated.
Link to comment
Share on other sites
6 answers to this question
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.