I am creating a leave system.

There are fields like:

  1. Type of leave as text
  2. From date as date
  3. To date as date and there is a calculated column named 'RequestedDays' which calculates the number of leave days requested excluding weekends.

Now, I need a field in the edit form which dynamically updates to 8*'RequestedDays' as soon as requestor enters his From date and To date.

I would also like to edit this 'leave hours' field manually and then submit to my manager for approval. How can I do this?

  • by the way I am using Sharepoint-online Commented Jan 15, 2019 at 20:33

2 Answers 2


The following example code for your reference.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
    var $fromDate=$("input[title='From date']");
    var $toDate=$("input[title='To date']");
    var $leaveHours=$("input[title='leave hours']");
    $fromDate.get(0).onvaluesetfrompicker = function(){
    $toDate.get(0).onvaluesetfrompicker = function(){
function getLeaveHours(fromDate,toDate){
    var count = 0;
    var startDate = new Date(fromDate);
    var endDate = new Date(toDate);
    while (startDate <= endDate) {
        var dayOfWeek = startDate.getDay();
        if(!((dayOfWeek == 6) || (dayOfWeek == 0)))
        startDate.setDate(startDate.getDate() + 1);
    return count*8;

enter image description here

  • But how can I integrate this js code into sharepoint-online? I am unable to find any html file that can display my form layout. Do you know how to do this in power-apps? Commented Jan 16, 2019 at 13:34
  • If you use modern UI in list form, we can't add JavaScript code to achieve it. We can't use JavaScript code in PowerApps.
    – LZ_MSFT
    Commented Jan 17, 2019 at 1:33

I got the answer. It can be done in Powerapps where you can customize your form. I added that 'Calculated Hours' field and was able to get result dynamically. Here are following threads that can help:




Note that the sharepoint formulas are not the same as Powerapps formulas

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.