lmooring Posted November 10, 2014 Report Share Posted November 10, 2014 Hi I am looking to see if there is a script that would do a date check between two to dates entered into a submission form. I need to have a check to see if date A is a minimum of 2 days prior to date B. If it's not the form can not be submitted and an alert message appears. I attempted to modify a couple other scripts I found but was unsuccessful at getting them to work. Any assistance would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Jan Posted November 11, 2014 Report Share Posted November 11, 2014 Hello Liz, If I understand correctly what is the goal, you can try this code: <SCRIPT LANGUAGE="JavaScript"> function checkStart() { var v_aDate = document.getElementById("InsertRecordA").value; var v_bDate = document.getElementById("InsertRecordB").value; var aDate = new Date(v_aDate); var bDate = new Date(v_bDate); bDate.setDate(bDate.getDate()-3); if (aDate>bDate) { alert("date A should be a minimum of 2 days prior to date B"); return false; } } document.getElementById("caspioform").onsubmit=checkStart; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
lmooring Posted November 11, 2014 Author Report Share Posted November 11, 2014 Hi Jan, Thank you so much this works perfectly stand alone but it appears to be stopping my other date check script. I am pasting them both below. Perhaps you could offer some advice on getting both of these to work? They are both in the footer of my form: The one from above: <SCRIPT LANGUAGE="JavaScript"> function checkTenderDate() { var v_aDate = document.getElementById("InsertRecordTenderTurnOffDate_Web").value; var v_bDate = document.getElementById("InsertRecordInStoreSFA_End").value; var aDate = new Date(v_aDate); var bDate = new Date(v_bDate); bDate.setDate(bDate.getDate()-3); if (aDate>bDate) { alert("Tender Turn Off date should be a minimum of 2 days prior to SFA End date"); return false; } } document.getElementById("caspioform").onsubmit=checkTenderDate; </SCRIPT> The one already in the form: <SCRIPT LANGUAGE="JavaScript"> function checkStart() { var v_sDate = document.getElementById("InsertRecordInStoreSFA_Start").value; var v_eDate = document.getElementById("InsertRecordInStoreSFA_End").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("SFA start date must be greater than today"); return false; } else { if (eDate<sDate) { alert("SFA end date must be greater than SFA start date"); return false; } } } document.getElementById("caspioform").onsubmit=checkStart; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Jan Posted November 13, 2014 Report Share Posted November 13, 2014 Hello Liz, I have answered in another topic. 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.