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.


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
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.


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
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
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
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
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
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.
Chris
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) {Anyway, many thanks again!
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);
}
});
Chris
.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.