We can include calculation and some customizations in SharePoint default custom list using javascript. First, you need to retrieve user input in the column to be used in calculation by using following code.
$(“input[Title=’Unit Price’]”).val();
The column name can be changed at the title. In this case, we used column name called “Unit Price”
Once you retrieved the column, we need to assign the column value into the variable to be used for calculation later.
var up= $(“input[Title=’Unit Price1′]”).val();
var fr= $(“input[Title=’Forex Rate1′]”).val();
Use that variable to do calculations and assign to another variable as shown below:
var total = up1*fr1;
Once the calculations is done, retrieve the column needed to display the result and insert the variable.
$(“input[Title=’Total’]”).val(total);
If you like to make the column a read-only, add attr(“readonly”,”true”) after the code and followed by adding background color to differentiate the read only column by adding .css(‘background-color’,’#B2B2B2′);.
$(“input[title=’Total’]”).attr(“readonly”,”true”).css(‘background-color’,’#B2B2B2′);
Below is the sample form used auto calculation and read only column :
The formula used here is :
Unit Price1 x Forex Rate = Unit Price x Quantity = Amount
Want to learn more on how SharePoint can help your business? Contact US (link to enquiry) for FREE consultation.
Leave a Reply