Dear all,
I am using Chronoforms on Joomla and would like to add a JQuery custom code. Since Joomla moved from Mootools to JQuery, I have difficulties migrating the following code. Here's what it does:
In short, to register for a debate tournament, field values #debaters, #judges, #observers are multiplied (by a fee) and added together. The tricky part: there is a discount option for every judge you bring more than the number of teams. Now, the number value of teams itself (capped at three) is irrelevant to the fees except that if you bring +1 judge than teams (e.g. two teams and three judges), all judges get a discount of -€30. If you bring more than 2 (or more), the discount of -€50 applies to all judges. 'Singles' and 'extra nights' are accommodation values and are simply added to the sum total. All values should sho in [#fees_acc]
Original (Mootools), working properly:
window.addEvent('domready', function() {
$('debaters').addEvent('change', rekenen1);
$('judges').addEvent('change', rekenen1);
$('observers').addEvent('change', rekenen1);
$('singles').addEvent('change', rekenen1);
$('extra_nights').addEvent('change', rekenen1);
});
function rekenen1(){
var num_teams = $('teams').value;
var num_judges = $('judges').value;
var num_extras = num_judges - num_teams;
var discount = 0;
if(num_extras > 0) {
discount = 30;
if(num_extras > 1) {
discount = 50;
}
}
$('fees_acc').value = $('debaters').value * 220 + $('judges').value * (220 - discount) + $('observers').value * 350 + $('singles').value * 90 + $('extra_nights').value * 30;
$('due_oct').value = $('fees_acc').value / 2;
}
Attempted JQuery adaptation (fail):
jQuery(document).ready(function(jQ) {
jQ('#debaters').click( rekenen1 () {
jQ('#judges').click( rekenen1 () {
jQ('#observers').click( rekenen1 () {
jQ('#singles').click( rekenen1 () {
jQ('#extra_nights').click( rekenen1 () {
});
function rekenen1(){
var num_teams = jQ('#teams').val();
var num_judges = jQ('#judges').val();
var num_extras = num_judges - num_teams;
var discount = 0;
if(num_extras > 0) {
discount = 30;
if(num_extras > 1) {
discount = 50;
}
}
jQ('#fees_acc').val() = jQ('#debaters').val() * 220 + jQ('#judges').val() * (220 - discount) + jQ('#observers').val() * 350 + jQ('#singles').val() * 90 + jQ('#extra_nights').val() * 30;
}
I am a teacher, not a coder, so I just have to rely on forums and imitation and guessing. Any help would be much appreciated.
Greetings and best regards
Chris