0

I'm creating a list that helps track employees projected hours they spend on projects as well as holiday, training and vacation hours. However the holiday field is part of a look up from another list. I also need the totals to show as employees fill out the form, not after they save it. So the Calculate Column does not work for this particular form. I know JavaScript can help but do not know how to have it calculate the regular columns and the lookup column. I will also then need to compare and validate against another lookup column. Can anyone help write that code?

Thanks

1 Answer 1

0

The following example for your reference.

1.Create a custom list, and add lookup column "holiday", number columns "training","vacation" and "totals" into list.

2.Add the following code into script editor web part in new/edit form page.

<script src="http://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
function PreSaveAction() { 
    var holiday= $("select[title='holiday'] option:selected").text();
    var training= $("input[title='training']").val();
    var vacation=$("input[title='vacation']").val();
    var totals=parseInt(holiday)+parseInt(training)+parseInt(vacation);
    alert("Totals:"+totals);
    $("input[title='totals']").val(totals);
    return true;
}
</script>

3.Click the save button we can see the "totals" value.

enter image description here

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.