1
0
-1

Hi

i have a select box (pre-populated) called Priority, with values P1,P2,P3,P4

in the same form i have two date pickers first Date_Occured second Expected_Completion_Date

based on Priority , i want to add 15,30,45,60 days to the Date_Occured date in to the Expected_Completion_Date

my code is so far

<script type="text/javascript">
$('[name$=Priority]').change(function() {
	var mySelectedValueId = $(this).find(':selected').val();
	
    if((mySelectedValueId === "P1"))
    {
        Days = 15
    }
    if((mySelectedValueId === "P2"))
    {
        Days = 30
    }
    if((mySelectedValueId === "P3"))
    {
        Days = 45
    }
    if((mySelectedValueId === "P4"))
    {
        Days = 60
    }
	var dateField = FormUtil.getField("Date_Occured");
	
	$('[name$=SelectedValueId]').val(mySelectedValueId);

	var mySelectedValueText = $(this).find(':selected').text();

	var instance = $(field).data( "Expected_Completion_Date" );
    
    var date = $.Expected_Completion_Date.parseDate(instance.settings.dateFormat || $.Expected_Completion_Date._defaults.dateFormat, selectedDate, instance.settings);
    
    date.setDate(date.getDate() + Days);
    
    $.Expected_Completion_Date.setDefaults(
        {
            onSelect: function( selectedDate ) 
        {
            updateDueDate(this, selectedDate);
        }
        }
});
</script>

but im not getting any update on the Expected_Completion_Date date picker.

any help is highly apricated

Thanks in advance

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      The variable "field" is not defined.

      var instance = $(field).data( "Expected_Completion_Date" );

      The last block has uneven bracket / syntax problem.

      $.Expected_Completion_Date.setDefaults(
              {
                  onSelect: function( selectedDate ) 
              {
                  updateDueDate(this, selectedDate);
              }
              }

      Something is not right with you code.

      The last block to add days to a date, try https://stackoverflow.com/questions/2706125/javascript-function-to-add-x-months-to-a-date

        CommentAdd your comment...