Search code examples
javascriptjqueryformsdatepickersharepoint-2013

Set EndDate value in SharePoint 13 to equal start date selected value


Working on a project in SP13 where calendar events are being set to all day events by default and all fields bar start date and title are hidden.

Issue is using the datepicker to select a start date in the future does not update the end date text field value, meaning it errors out when saving as end date cannot be earlier than start date. End date needs to be hidden so users can't manually set it to days other than the start date.

No success using jQuery so far. Looking for help.


Solution

  • You could use the below script to set end date to equal start date:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
    function PreSaveAction(){
    var startDate = $('input[title="Start Time Required Field"]').val();
    $('input[title="End Time Required Field"]').val(startDate);
    return true;
    }
    
    </script>