ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Really small custom jQuery not working

CrystalFrontier 29 Dec, 2018
Dear all,

In CF V6, I'm trying to do a little calculation and show the result in a field ID called 'total'. The number of females and the numbers of males at an event times a price (84.00) add up to a sum total. Since the numbers are limited, they are selected from a dropdown. I somehow suspect that's the issue but can't tell why. The IDs are double-checked and so are values.

The code is as follows:[pre]jQuery(document).ready(function(){
[br] jQ('#_of_female_debaters').change(calculate);[br] jQ('#_of_male_debaters').change(calculate);[br][br]function calculate(e)[br]{[br] jQ('#total').html(jQ('#_of_female_debaters').val() * 84 + jQ('#_of_male_debaters').val() * 84);[br]}[br]});[/pre]
I have tried two online jQuery editors and checks, and they all confirm the correctness of the code. However, it is not working in my form. The total text field stays empty.

SL_1.png

SL_2.png

What does the 'Add inside Domready' tickbox mean? It doesn't seem to make a difference, but it may be connected.

Many thanks for the help![br]Chris
GreyHead 29 Dec, 2018
Hi Chris,

Are you using '#_of_female_debaters' or '_of_female_debaters' as the id for the field - if so, please change it so that it does not start with # or _

Bob
CrystalFrontier 29 Dec, 2018
Hello Bob,

Thanks for the fast response.

I have changed both name and ID of the field to of_female_debaters but that didn't bring any change. The hashtag, I believe, needs to remain in the code as a selector indicator, now being ('#of_female_debaters').

Have I maybe placed the JS custom code wrong? It is at the very top of the design section.

Chris
CrystalFrontier 29 Dec, 2018
Ha, I've just copy&pasted from an earlier version I did this summer. It's working now!!

But where's the difference?? Is it .val in stead of .html in ('#total')? I know I swapped these through with no effect, but I can't get my head around it. Weird.
jQuery(document).ready(function(jQ) {
jQ('#of_female_debaters,#of_male_debaters,#total').change(fees);

function fees() {

jQ('#total').val(jQ('#of_female_debaters').val() * 84 + jQ('#of_male_debaters').val() * 84);
}
});
Anyway, many thanks again!
Chris
healyhatman 30 Dec, 2018
.html() sets the inner code of an element, .Val() sets the value. If you were using say a div to display the result you would use .html
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com