JS to fill form field with value

admin_wiky 27 Apr, 2018
Hello to everyone,

I have a form where I need to SUM two form fields to the third field - automatically after filling the fields before SUBMIT.
I am trying with this code :
$('.price').keyup(function () {
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
form fields has 'price' in class and resulting field has id 'nezalistovane_0_cena_celkem'
but it doesnt works.

could you help me?
GreyHead 27 Apr, 2018
Hi homeopat,

I suggest that you use your browser web developr tools to debug your script. You can also add some debug lines to the code to see exactly what is happening.

healyhatman 27 Apr, 2018
Try replacing "$(" with "jQuery("
admin_wiky 02 May, 2018
Bob: what debug liners do you mean? I am using standart Debug on
Healyhatma: didnt help

I did try this
jQuery(document).ready(function() {
jQuery('.form-control A').keyup(function () {

var sum = 0;

jQuery('.form-control A').each(function() {
sum *= Number(jQuery(this).val());


but still not working.
I forgot said that these fields are in multiplier.

healyhatman 02 May, 2018
Where have you put this code? Have you tried custom javascript element in Designer, with document ready switched on? (And then obviously take out the jQuery(document).ready you have in there

Also and much more importantly: ('.form-control A') probably won't actually select anything, except maybe an "A" element (<a> ?)
inside an object with class form-control. Need to fix your selector.
admin_wiky 02 May, 2018
I put this code to setup section - on load js script. I am not good in JS, so no I didnt try.
form-control A is name of the class of form fields . you have right, that the selector is not fixed, because each element has class form-control A. So I add to the mentioned field prefix price to the class.
healyhatman 02 May, 2018
Names of things can't have spaces in them
admin_wiky 02 May, 2018
but form-control A is made by chronoengine automatically.
healyhatman 02 May, 2018
You'll have to trust me on this buddy - you can't have spaces in a name. You've probably put a space in when you've named the items.
admin_wiky 02 May, 2018
form-control A is not fill in class item (Builder). I have it empty and then I see form-control A in code in this item. when I add price to the class item in builder, then I see price form-control A in code of page.
Maybe we dont understand to each other.
healyhatman 02 May, 2018
Post pictures - of how you have the field set up in Designer, and of how the HTML code looks.
admin_wiky 02 May, 2018
Here is example of 1 field in builder

<input name="nezalistovane[0][ks]" id="nezalistovane_0_ks" value="" placeholder="" maxlength="11" size="3" class="price form-control A" title="" style="" data-inputmask="" data-load-state="" data-tooltip="" type="text">
healyhatman 02 May, 2018
OK I see now - It's two classes.
admin_wiky 02 May, 2018
3 classes when I set price in builder of item .... i have other fields in form, what I dont need to count.
This topic is locked and no more replies can be posted.