Need some help with a table-dv.js file
Posted: 2019-03-23 19:13
Hello to all the coding experts out there,
I am still working on the same project but have hit another conundrum. I have a detail view with some simple equations that I need to group together for one final total. I have a MyTable-dv.js file that I have been working on. There are some catches though.
1. The first part is fairly easy and with the current help files posted on the AppGini site I was able to solve. It is basic math with 3 pulldown fields needing to be summed in a subtotal field. Here is the code I have for that:
$j(function(){
/* Set SubTotal1 field as read-only to avoid user editing */
$j('# SubTotal1').prop('readonly', true);
/* recalculate SubTotal1on updating Field1, Field2 or Field3*/
$j('#Frequency, #Severity, #Exposure').change(function(){
var Frequency = parseFloat($j('#Field1).val()) || 0;
var Severity = parseFloat($j('#Field2').val()) || 0;
var Exposure = parseFloat($j('#Field3').val()) || 0;
var SubTotal1 = Math.round (Field1 + Field2 + Field3) ;
$j('#SubTotal1').val(SubTotal1);
});
/* Calculate Subtotal on opening the detail view form */
$j('#Field1').change();
$j('#Field2').change();
$j('#Field3').change();
})
2. I have 3 additional fields that are multiple choice list boxes. I have been trying to have it so when they are not populated, they would be zero and the moment that each is populated (regardless of how many choices are selected) each would be given a distinct value. The once summed they would become SubTotal2 . The fields are:
• ControlField1 – Would like to see this as a total of 3 when populated and zero if empty (null)
• ControlField2 – Similar to above but 2 if populated and zero otherwise
• ControlField3 – Finally, 1 if populated and zero if empty
So the equation would be SubTotal2 = ControlField1(value of 3) + ControlField2(value of 2) + ControlField3(value of 1). I have nothing to show here as so far I have been unsuccessful.
3. Finally I would like to Have a final total that would be GrandTotal = Subtotal1 – SubTotal2
I tried this in the same MyTable-dv.js file but it hasn’t worked:
/* Set GrandTotal field as read-only to avoid user editing */
$j('#GrandTotal').prop('readonly', true);
/* recalculate GrandTotal on updating SubTotal1 and SubTotal2*/
$j('#SubTotal2').change(function(){
var SubTotal = parseFloat($j('#SubTotal2').val()) || 0;
var Adjustment = Math.round (SubTotal1 – SubTotal2) ;
$j('#GrandTotal').val(GrandTotal);
});
/* Calculate SubTotal2 on opening the detail view form */
$j('#SubTotal2').change();
I wanted to see if I could just put a number in the SubTotal2 field and make the equation work. All I achieved was a NaN total in the GrandTotal field.
Thanks in advance.
If I need to pay someone for the assistance, I am willing to work out something. However, it all depends on how much. I am not working at the moment and building this on sweat equity.
I am still working on the same project but have hit another conundrum. I have a detail view with some simple equations that I need to group together for one final total. I have a MyTable-dv.js file that I have been working on. There are some catches though.
1. The first part is fairly easy and with the current help files posted on the AppGini site I was able to solve. It is basic math with 3 pulldown fields needing to be summed in a subtotal field. Here is the code I have for that:
$j(function(){
/* Set SubTotal1 field as read-only to avoid user editing */
$j('# SubTotal1').prop('readonly', true);
/* recalculate SubTotal1on updating Field1, Field2 or Field3*/
$j('#Frequency, #Severity, #Exposure').change(function(){
var Frequency = parseFloat($j('#Field1).val()) || 0;
var Severity = parseFloat($j('#Field2').val()) || 0;
var Exposure = parseFloat($j('#Field3').val()) || 0;
var SubTotal1 = Math.round (Field1 + Field2 + Field3) ;
$j('#SubTotal1').val(SubTotal1);
});
/* Calculate Subtotal on opening the detail view form */
$j('#Field1').change();
$j('#Field2').change();
$j('#Field3').change();
})
2. I have 3 additional fields that are multiple choice list boxes. I have been trying to have it so when they are not populated, they would be zero and the moment that each is populated (regardless of how many choices are selected) each would be given a distinct value. The once summed they would become SubTotal2 . The fields are:
• ControlField1 – Would like to see this as a total of 3 when populated and zero if empty (null)
• ControlField2 – Similar to above but 2 if populated and zero otherwise
• ControlField3 – Finally, 1 if populated and zero if empty
So the equation would be SubTotal2 = ControlField1(value of 3) + ControlField2(value of 2) + ControlField3(value of 1). I have nothing to show here as so far I have been unsuccessful.
3. Finally I would like to Have a final total that would be GrandTotal = Subtotal1 – SubTotal2
I tried this in the same MyTable-dv.js file but it hasn’t worked:
/* Set GrandTotal field as read-only to avoid user editing */
$j('#GrandTotal').prop('readonly', true);
/* recalculate GrandTotal on updating SubTotal1 and SubTotal2*/
$j('#SubTotal2').change(function(){
var SubTotal = parseFloat($j('#SubTotal2').val()) || 0;
var Adjustment = Math.round (SubTotal1 – SubTotal2) ;
$j('#GrandTotal').val(GrandTotal);
});
/* Calculate SubTotal2 on opening the detail view form */
$j('#SubTotal2').change();
I wanted to see if I could just put a number in the SubTotal2 field and make the equation work. All I achieved was a NaN total in the GrandTotal field.
Thanks in advance.
If I need to pay someone for the assistance, I am willing to work out something. However, it all depends on how much. I am not working at the moment and building this on sweat equity.