Forums

Field that multiplies a variable inserted in a previous field

nick_ingenia 05 Jun, 2014
Hello,
I want to have a chronoform field (in my form) that will automatically moltiplicate a numeric variable inserted in a previous field.

Exaple:
FORM
Field 1: number_of_plants
Field 2: 0,60 (cost for each plant) * number_of_plants

So....

Field 1: 10 (inserted by user)
Field 2: 6

Field 2 will be read-only field, displayed in the form.

Is it possibile? Thanks
GreyHead 05 Jun, 2014
Hi nick_ingenia,

Yes, you can do that by adding custom JavaScript to your form.

Bob
nick_ingenia 06 Jun, 2014
Thanks GreyHead, I know how to add custom Javascript on action (CUSTOM CODE) or in element (CUSTOM ELEMENT HTML/PHP) but I don't know JavaScript language. Please can yuou help me? Can you get me the js code?
GreyHead 06 Jun, 2014
Hi nick_ingenia,

It will be something like this:
window.addEvent('domready', function() {
  $('number_of_plants').addEvent('keyup', function() {
    $('total').value = parseInt($('number_of_plants').value) * 0.6;
  });
});
You need to set ids for both inputs for this to work. Here I've used 'number_of_plants' and 'total'.

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