Forums

Calculation

WR 20 Nov, 2015
Hi,

i tried a few solutions but I have somewhere a mistake.
i what to add first just!!! two fields..
script was found here at the board..

Where is my error?
GreyHead 20 Nov, 2015
HI WR,

The JavaScript you found is using the MooTools library which Joomla! has stopped using in Joomla! 3. Instead they are using jQuery. Here's a similar script using jQuery
jQuery(document).ready(function(jQ){
  jQ('#firstBox').on('keyup', calcTotal);
  jQ('#secondBox').on('keyup', calcTotal);

  function calcTotal() {
    var first_box, second_box, total;
    first_box = jQ('#firstBox').val();
    if ( !jQ.isNumeric(first_box) ) {
      first_box = 0;
    }
    second_box = jQ('#secondBox').val();
        if ( !jQ.isNumeric(second_box) ) {
      second_box = 0;
    }
    total = parseFloat(first_box) + parseFloat(second_box);
    total = total.toFixed(0);
    jQ('#thirdBox').val(total);
  }
});

I would set the thirdbox to readonly*, and add masks to the other two inputs.

Bob

* Put readonly=readonly in the Extra Params box
WR 21 Nov, 2015
Hi and thanks for the tipps.
i made all changes but still no function..
GreyHead 21 Nov, 2015
Hi WR,

Please check for JavaScript errors on the page, You can see my test form working with this JavaScript here - so the basic code should be OK.

Bob
WR 25 Nov, 2015
Hi, thanks for your Help.
I still canĀ“t find my problem..

i made a backup ... please have a look
GreyHead 25 Nov, 2015
Hi WR,

You have the form set to Custom Code in the Code tab - and the element IDs in the custom HTML there are different from those you have in the Designer tab. If you switch the form back to 'Wizard Designer' then it works correctly.

Bob
WR 25 Nov, 2015
Great... it Works...
Thanks for the very quick help...
This topic is locked and no more replies can be posted.