Preface - I'm no programmer. Having a heck of a time adding field values together. They want to concat instead of add. I followed the instructions found here https://www.chronoengine.com/forums/posts/t65691/p266274.html#p266274 and ran into two problems.
1. The math was wrong for some multipliers. For example, 19.95 x 3 would result in: 59.849999999999994. So I added $('variable_here').value = Math.round($('gtotal1').value * 100) / 100; and that seems to work. Is this a proper solution?
2. I have a grand total field that I can not get to add instead of concat. The form is set up with 12 multi fields. Each has a predefined value (price) a user defined value (quantity) and a total value (price x quantity). These work fine. The form has a "grand total" field that is supposed to show the calculated total of all the total fields. This is where the problem lies.
Example: Line A price 1 is 19.95. User selects 3. Total value for line A is 59.85. Line B price is 1.00. User selects 3. Total value for Line B is 3.00. Grand Total is 59.853 instead of 62.853.
I tried adding validators through the designer view. I validated "number" for all number fields. It made no difference.
I found a few ways to force number instead of string but can't seem to get the syntax right. Partly because I don't understand what the $ is doing - I believe it is referencing a method - so that may be a conflict when using parseFloat for example.
Here is a shortened (2 lines instead of 12) version of my code (I'm sure it could be shortened and improved - but this works - but for the concat issue. All tips welcome!). Note I left the non functioning parseFloat in there so you could see how I was attempting to use it.
LAST - the function total_all is currently being called by a radio button click. Is there a way to call this from any field input? Example, user input of quan1 or quan2 etc.
1. The math was wrong for some multipliers. For example, 19.95 x 3 would result in: 59.849999999999994. So I added $('variable_here').value = Math.round($('gtotal1').value * 100) / 100; and that seems to work. Is this a proper solution?
2. I have a grand total field that I can not get to add instead of concat. The form is set up with 12 multi fields. Each has a predefined value (price) a user defined value (quantity) and a total value (price x quantity). These work fine. The form has a "grand total" field that is supposed to show the calculated total of all the total fields. This is where the problem lies.
Example: Line A price 1 is 19.95. User selects 3. Total value for line A is 59.85. Line B price is 1.00. User selects 3. Total value for Line B is 3.00. Grand Total is 59.853 instead of 62.853.
I tried adding validators through the designer view. I validated "number" for all number fields. It made no difference.
I found a few ways to force number instead of string but can't seem to get the syntax right. Partly because I don't understand what the $ is doing - I believe it is referencing a method - so that may be a conflict when using parseFloat for example.
Here is a shortened (2 lines instead of 12) version of my code (I'm sure it could be shortened and improved - but this works - but for the concat issue. All tips welcome!). Note I left the non functioning parseFloat in there so you could see how I was attempting to use it.
window.addEvent('domready', function() {
$('quan1').addEvent('input', rekenen1);
$('quan2').addEvent('input', rekenen2);
}
function rekenen1(){
$('gtotal1').value = $('quan1').value * $('price1').value;
$('gtota1').value = Math.round($('gtotal1').value * 100) / 100;
parseFloat($('gtotal1').value);
}
function rekenen2(){
$('gtotal2').value = $('quan2').value * $('price2').value;
$('gtota2').value = Math.round($('gtotal2').value * 100) / 100;
parseFloat($('gtotal2').value);
function total_all(){
$('betrag').value = $('gtotal1').value + $('gtotal2').value;
$('betrag').value = Math.round($('betrag').value * 100) / 100;
parseFloat($('betrag').value );
}
}
LAST - the function total_all is currently being called by a radio button click. Is there a way to call this from any field input? Example, user input of quan1 or quan2 etc.