JS calculation in chronoforms V5

alec6w 22 Apr, 2014
Hello,

I try to make a form with this JS code found in your forum.


    window.addEvent('domready', function() {
      $('prixrouge').addEvent('keyup', calc);
      $('qterouge').addEvent('keyup', calc);
    });
    function calc() {
      var price = $('prixrouge').value;
      var quantity = $('qterouge').value;
      if ( price > 0 && quantity > 0 ) {
        $('total_rouge').value = $price * $quantity;
      }
    });


I put it in a load 'JS event' before the event 'HTML render form'.
Nothing happens.

Any ideas ?
GreyHead 22 Apr, 2014
Hi alec6w,

The JavaScript looks OK, impossible to say anything else without looking at the form. Do you see any errors in the JavaScript console in your browser web developer tools?

Bob
alec6w 22 Apr, 2014
Thanks for you quick reply.
Your answer help me.
There was some errors in my JS code.
Here the correct code.

    window.addEvent('domready', function() {
      $('prixrouge').addEvent('keyup', calc);
      $('qterouge').addEvent('keyup', calc);
    });
    function calc() {
      var price = $('prixrouge').value;
      var quantity = $('qterouge').value;
      if ( price > 0 && quantity > 0 ) {
        $('totalrouge').value = price * quantity;
      }
    }
GreyHead 22 Apr, 2014
Hi alec6w,

Well found - I completely missed the extra $s :-(

Bob
This topic is locked and no more replies can be posted.