Jump to content

Date Field Validation


Recommended Posts

I'm looking for help with validating a date field on a submission form.  If the user enters a value less than the current date, an alert message appears and the form will not submit.  Please provide a javascript solution if you have used something like this in one of your applications.  Thanks, Chris.

Link to comment
Share on other sites

You can try to add an HTML Block at the end of the list and have this code in:

<script>
function chk_date(){
if ( new Date(document.getElementById('InsertRecordDATEFIELDNAME').value) < new Date() )
{
 alert("Select a day after now !");
 document.getElementById('InsertRecordDATEFIELDNAME').value = null;
 return false;
}
else {document.getElementById('caspioform').submit();}
}

</script>

<input type="button" onclick="chk_date()" value="Submit">

You need to hide the default submit button in the style by adding display:none; to .cbSubmitButton

 

Make sure to replcae DATEFIELDNAME with the actual field name

 

:rolleyes: :rolleyes: :rolleyes:

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
  • 10 months later...

I am trying to set a lower end limit on the date that can be selected. Below is the code I tried it has yet to work.

 

It is being run in conjunction with concatenate script.

 

 

function validateDate() {

var date = document.getElementById('InsertRecordDate').value;

 

if (Date.parse(del_date) < Date.parse("08/07/2015"))

{ alert("Please enter a date after 08/07/2015"); } }

 

document.getElementById('InsertRecordGuestOrders_Delivery_date').onChange = validateDate();

 

 

Any suggestions would be greatly appreciated.

 

Thanks

Link to comment
Share on other sites

  • 4 weeks later...

Hi ychaudhry,

 

As far as I can understand, the incorrect variable is used in the condition:

 

var date = document.getElementById('InsertRecordDate').value;

if (Date.parse(del_date)

 

I would like to recommend you either change "var date" to "var del_date" or change "(Date.parse(del_date)" to "(Date.parse(date)".

 

I hope, it helps.

Link to comment
Share on other sites

  • 7 years later...
  • 9 months later...

  

Just to add on this if you wish to disable future dates you may use the exact code below.

Header
 

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">

<!-- jQuery -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
 <!--  Flatpickr  -->
  <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>




Footer
 

<script>

      $("#DATETIMEFIELD").flatpickr({
    dateFormat: "d/m/Y",
    altInput: true,
    altFormat: "m/d/Y",
    maxDate: "today"
  });
</script>

 

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
Reply to this topic...

×   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...
×
×
  • Create New...