Need help to build a script to divide two integer fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2014 11:38 AM
How do you divide two integer fields to get a value in a separate field? For example, field1=10, field2=5. I want to divide field1 from field2 and have the value in field3.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2014 10:00 AM
var StartNumber = '444,555,666';
var ReplacedNumber = StartNumber.replace(/\,/g,'');
document.write(ReplacedNumber);
The above shows how a regular expression can be used in JavaScript to remove the commas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2014 09:34 AM
I did change the field C from integer to decimal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2014 09:40 AM
I also tried changing field A and B from integer to decimal but it made no difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2014 10:12 AM
Hi Tim,
Forgive me but I cannot program in javascript! Do I add that to the onload script? If so, what lines should I add them in? Below is the onload client script...
function onLoad() {
//do nothing, just loading the function below
}
function divide_a_by_b() {
var a = parseInt(g_form.getValue('u_total_test_count___ca'),10);
var b = parseInt(g_form.getValue('u_total_req_count___ca'),10);
var result = 0; // force to zero if infinite
if (b != 0) {
var result = (a/b).toFixed(2);
}
g_form.setValue('u_avg_test_req_count___ca',result);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2014 01:28 PM
Try:
function onLoad() {
//do nothing, just loading the function below
}
function divide_a_by_b() {
var first = g_form.getValue('u_total_test_count___ca');
first = first.replace(/\,/g,'');
var second = g_form.getValue('u_total_req_count___ca');
second = second.replace(/\,/g,'');
var a = parseInt(first,10);
var b = parseInt(second,10);
var result = 0; // force to zero if infinite
if (b != 0) {
var result = (a/b).toFixed(2);
}
g_form.setValue('u_avg_test_req_count___ca',result);
}
Hopefully my cutting and pasting didn't break something. I don't know that you still need to do the parseInt.