Is it possible to Chronoforms to add values from fields ?

Repitol 19 Feb, 2013
Hi,
In my form, user can register to different activities (one field for each). Theses activities have different costs.
at the very end of the form, user has to calculate the amount to pay depending on the activities he chose.
I don't think this is possible but is there a way to add automatically numbers from different fields in the last field ?
Thanks for your job !
Chronoforms_V4_RC3.5.1_J1.5
(5 domains Subscription licence)
GreyHead 19 Feb, 2013
Hi Repitol,

Yes, you can use JavaScript to do that. You'll find some examples here if you search on 'calculate' (try the ChronoSearch from the Tutorials link above). You'll find many more if you use Google search generally.

Each calculation is different so it's not possible to provide much more than very general help here.

Bob
Repitol 19 Feb, 2013
Hi Bob,
thanks for your quick reply !
That's great ! I need a very simple method for a simple form
eg:
field A - price in euro (text box) : 20
field B - price in euro (text box) : 30
total to be paid (Field C) : 50

That's all. I'll take a look at the search as you suggest
Best regards
Repitol
GreyHead 19 Feb, 2013
Hi Repitol,

And the IDs of those inputs are . . . ?

Bob
Repitol 19 Feb, 2013
Sorry,
here is the JS code I tried but it seems there's a problem. The last field ('total_a_payer') stays empty.
I put this code in a Load JS action within the OnLoad event
Id's are those declared in "Field Id" area for each input

Do I have to change anything in fields (configuration / General) ?

window.addEvent('domready', function() {
  $('total_soiree_dansante').addEvent('change', rekenen1);
  $('total_coupe').addEvent('change', rekenen1);
   $('total_ski_seul').addEvent('change', rekenen1);
    $('total_buffet').addEvent('change', rekenen1);
     $('total_soiree_pyreneenne').addEvent('change', rekenen1);
      $('total_ski_libre').addEvent('change', rekenen1);
});
function rekenen1(){
  $('total_a_payer').value = $('total_soiree_dansante').value + $('total_coupe').value + $('total_ski_seul').value + $('total_buffet').value + $('total_soiree_pyreneenne').value + $('total_ski_libre').value;
}


Repitol confused....
GreyHead 20 Feb, 2013
Hi Repitol,

The code looks OK to me.

Do you see any errors in the JavaScript Console in your web browser?

Bob
Repitol 20 Feb, 2013
Hi,
Error message !! Right !
Horodatage : 20/02/13 10:15:25
Erreur : TypeError: $(...) is null
Fichier Source : (here is the website url)
Ligne : 62


Maybe something I miss but I don't know where unfortunately.
Every Field Ids are checked and are ok (in text boxes / configure / general / FieldID)
The code is on LoadJS event (OnLoad panel)
Form saved.
No code in the last field (total-a-payer) except FieldID. This field is a text box.

When I use the form, whatever the number I write, the last field stays empty.

Don't know what to check... 😟
GreyHead 20 Feb, 2013
Hi Repitol,

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

Bob
GreyHead 20 Feb, 2013
Hi Repitol,

There is no element with the id=total_ski_libre, it's in the title attribute instead of the id:
<input type="text" name="input_text_69" value="" title="total_ski_libre" class=" validate['required','number']" size="30" maxlength="150">

Bob
Repitol 20 Feb, 2013
Well seen.😶
I've changed it, saved, but it still doesn't work.
GreyHead 20 Feb, 2013
Hi Repitol,

It's working OK here but concatentating the values i.e. 15+48 = 1548 instead of adding them. Please try
$('total_a_payer').value = parseInt($('total_soiree_dansante').value) + parseInt($('total_coupe').value) + parseInt($('total_ski_seul').value) + parseInt($('total_buffet').value) + parseInt($('total_soiree_pyreneenne').value) + parseInt($('total_ski_libre').value);

Bob
Repitol 20 Feb, 2013
Bob,
with your new code there's a big change : the field calculates !
but the result is still wrong
60 + 25 + 22 + 50 + 100 + 220 = 60252250100220

you're close to fix my problem !
Repitol 20 Feb, 2013
Sorry, it doesn't calculate anymore.
I've tried a new test but the field stays empty. I'm really confused.

the code I use
window.addEvent('domready', function() {
  $('total_soiree_dansante').addEvent('change', rekenen1);
  $('total_coupe').addEvent('change', rekenen1);
   $('total_ski_seul').addEvent('change', rekenen1);
    $('total_buffet').addEvent('change', rekenen1);
     $('total_soiree_pyreneenne').addEvent('change', rekenen1);
      $('total_ski_libre').addEvent('change', rekenen1);
});
function rekenen1(){
 $('total_a_payer').value = parseInt($('total_soiree_dansante').value) + parseInt($('total_coupe').value) + parseInt($('total_ski_seul').value) + parseInt($('total_buffet').value) + parseInt($('total_soiree_pyreneenne').value) + parseInt($('total_ski_libre').value);}
Repitol 20 Feb, 2013
IT WORKS !!
I've tried on Safari and it calculates with no error

tried on Firefox, empty caching, it stays with empty field. maybe a problem with my Firefox caching.

I'll make another test and gives you the result.
Repitol 20 Feb, 2013
Ok Bob,
that's ok. It works fine. 😀
Thanks again for the time you gave me.
Have a good day !
Repitol 21 Feb, 2013
Hi Bob,
last question : How can I put € sigle automatically in the last field (total_a_payer) ?
With current code, the field shows only the amount
I'd like amount in € like 230€ and not only 230.
Thanks
(I've noticed a bug with email value when using print button code given in your FAQ. on the print, email appears twice ie: [email]bob@chronoengine.combob[/email]@chronoengine.com)
Maybe you have a fix for that ?
Thanks
best regards
Repitol
GreyHead 21 Feb, 2013
Hi Repitol,

You could just add the HTML for a euro sign at the end of the string you calculate in the JavaScript.

There's nothing in the print code that will duplicate the email address - it may be because you have the Joomla! Email cloaking plugin turned on?

Bob
Repitol 21 Feb, 2013
well, the HTML code for € is

when I use it in the JS code and apply, it turns to € and the JS doesn't work anymore.
I think that's because I don't put it at the good place, I'm under newbee level at Javascript.

So I put it in the form html code (form edit not wizard mode) and it goes well).🙂

Joomla! Email cloaking plugin
Wazaaat ? :?

When using Thanks Message template after subit, it shows e-mail with no problem
(called by string
<td>{email}</td>
)

when I use "print button"
page shows and print emailemail (maybe because it uses
<a href="mailto:email">email</a>
?)
GreyHead 21 Feb, 2013
Hi Repitol,

Please try:
. . .
$('total_a_payer').value = parseInt($('total_soiree_dansante').value) + parseInt($('total_coupe').value) + parseInt($('total_ski_seul').value) + parseInt($('total_buffet').value) + parseInt($('total_soiree_pyreneenne').value) + parseInt($('total_ski_libre').value) + ' €';
. . .

Bob
Repitol 22 Feb, 2013
Hi Bob,
no, with that code it shows for example : 220 &euro
I just tried to replace ' €' with '€'
and it works.
thanks !
I now open another post cause I have another question about interaction between 2 fields 😶
This topic is locked and no more replies can be posted.