Forums

Calculation in multifield

Sylcom 09 Sep, 2015
Hello,
I would like to calculate in multi field.

I have two columns with seven rows

The textbox of the first row of the first column has the ID text320
The textbox of the first row of the second column has the ID text330

The textbox of the second row of the first column has the ID text321
The textbox of the second row of the second column has the ID text331, and so for the following rows.

When I write a number in the first column I would to have the result in the second column.

text330=text320*130
text331=text321*155 and so for the following rows.

I put this in LoadJavaScript in OnLoad for the first row.
window.addEvent('domready', function() {
      $('text320').addEvent('change', calc);
    });
    function calc() {
      var price = 130;
      var quantity = $('text320').value;
      if ( price > 0 && quantity > 0 ) {
        $('text330').value = price * quantity;
      }
    }
Nothing happens.

Is someone able to help me, and show me for the two first rows. I think that I could understand for the following rows.

Thanks per advance

Jean-Claude
Sylcom 09 Nov, 2015
Noboby can help me?
GreyHead 09 Nov, 2015
Hi Jean-Claude,

Your JavaScript is using the MooTools library syntax - Joomla! has dropped that in Joomla! 3 in favour of jQuery. The JavaScript will be something like this
jQuery(document).ready(function (jQ) {
  jQ('#text320').on('change', calc);

  function calc() {
    var price = 130;
    var quantity = jQ('#text320').val();
    if ( price > 0 && quantity > 0) {
      jQ('#text330').val( price * quantity);
    }
  }
});

Bob
Sylcom 09 Nov, 2015
Thank you Bob, I will try it this week
Sylcom 12 Nov, 2015
I tried, but nothing happens
GreyHead 12 Nov, 2015
Hi Jean-Claude,

Please post a link to the form so I can take a quick look.

Bob
Sylcom 12 Nov, 2015
It is only on my computer.

I send you a backup of the form, if you can use it.
GreyHead 13 Nov, 2015
Hi Jean-Claude,

+ The Load JavaScript action and Load CSS actions should probably be before the HTML (Render form) action.

+ You still have the old MooTools JavaScript in the form :-(
If I replace make these two changes then the script works - see the 100cm row here.

+ Also you have many elements where there are spaces or 'special' characters in the input names - these are not allowed and will break your form.

Use - for example - societe in place of Société
Use - for example - adresse_de_livraison in place of Adresse de livraison

This is just in the Name and ID boxes - spaces and special characters are OK as Labels,

+ If you want to put two or more inputs side by side you can use the MultField element - you do not need to use Columns in Containers.

+ Similarly it's probably simpler to create the table using a Custom Code element and hand-coding the HTML.

Bob

PS the price per stère looks expensive?
Sylcom 13 Nov, 2015
Hi Bob,

I thank you for all these answers.

I will do changes next week

The price is in swiss money and was gave by my friend who is the chief.

Have a nice journey and weekend

Jean-Claude
GreyHead 13 Nov, 2015
Hi Jean-Claude,

Ah - if it's Switzerland and Swiss francs then it may be a bargain ;-)

Bob
Sylcom 13 Nov, 2015
Yes, and Geneva is one of the most expensive place in Switzerland
Sylcom 20 Nov, 2015
Hello Bob,

Great! I've made the changes and it works fine.
I'will ask my friend for the following of the form.

Thank you very much

Have a nice day

Jean-Claude
This topic is locked and no more replies can be posted.