Jump to content
  • 0

Date Comparison In Submission Form


lmooring
 Share

Question

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

  • 1

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.

Link to comment
Share on other sites

  • 0

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>
Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...