|
How to Use Calculated Fields
A calculated field derives its value from some formula involving other fields values. You do not enter
data into a calculated field. The program automatically determines the correct value when involved records are changed.
There are two types of calculated fields:
1. Calculated field calculates "on the fly" and doesn't exist in database.
2. Calculated field exists in database and calculates using JavaScript.
1. Calculated field calculates "on the fly" and doesn't exist in database.
- proceed to SQL query tab and check off the Edit SQL query manually box.
- add your query. For example:
Price * Quantity as Total,
Price * 0.05 as Tax
- build project.
How it looks in browser:

2. Calculated field exists in database and calculates using JavaScript.
You can also add values calculated as per some formula to existing field in the database.
To do it, you need to make changes in the include/�_aspfunctions.asp and include/jsfunctions.js files.
For example, you need to calculate and add Sum = Price * Quantity. field value to the database
Open jsfunctions.js file and add the following code snippet to the very end of the file:
function UpdateSum()
{
document.editform.Sum.value = document.editform.Price.value *
document.editform.Quantity.value;
}
Open �_aspfunctions.asp file, find BuildEditControl Function, and modify the ASP code in its beginning (see changes in bold):
BuildEditControl =""
if sFieldName="Price" or sFieldName="Quantity" then
onchange = " onchange=""UpdateSum();"" "
end if
Select Case sFormat
Case EDIT_FORMAT_TEXT_FIELD
BuildEditControl = "<input type=text name=""" & sFieldName & """" & _
GetEditParams(sFieldName) & " value=""" & sDefault & """" & onchange & ">"
After changing Price or Quantity values on the Add/ Edit page value in the Sum field will be changed automatically.
Back to top
|