You are viewing limited content. For full access, please sign in.

Question

Question

Validate a Date Field to be Before or After Another Date Field [Forms] [9.2.0.908]

asked on February 3, 2015

Am I able to force a Date on my form to be before or after another Date on the same form?

Hopefully JavaScript isn't the only way, but if it is, please provide sample code.

0 0

Answer

SELECTED ANSWER
replied on February 5, 2015

Hi Eddie, 

 

Yes this will require JavaScript if you want the calculation to occur within the form. Here is some code to get you started. 

$(document).ready(function () {
   
 $('.startDate').on('change', 'input', calcDay);  
  
  function calcDay() {
     var d = new Date($('#Field1').val());
	 var NewDate = d.setDate(d.getDate() + 5);
   	 var Value = d.toLocaleDateString(NewDate);
    $('.NewDate input').val(Value);

  };
  
  }); 

This will always add five days to the input day. If you would like to have this change based on user input, you will need to add a number field and use it as a variable within this function. 

The class "startDate" was applied to the input date field and the class "NewDate" was put on the output date field. 

I hope this helps!

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.