Tell us what you are trying to do?
I need to multiply the value of two custom fields with JavaScript and display the result in a third custom field in a CRED form
jQuery( function( $ ) {
$('input[name=menge]').change(compute);
$('input[name=produktpreis]').change(compute);
function compute() {
if ( $('input[name=produktpreis]').val() != undefined ) {
var a = $('input[name=menge]').val();
var b = $('input[name=produktpreis]').val();
var gesamtpreis = a * b;
$('input[name=gesamtpreis]').val(gesamtpreis);
}
}
} );
Hello. Thank you for contacting the Toolset support.
The thing is that if you created the custom fields using Types plugin the Types fields have prefix wpcf-
So, the field name menge should actually be accessed using name wpcf-menge.
Can you please try to add prefix wpcf- to your all custom fields and check if that help you to resolve your issue.
For example:
jQuery( function( $ ) {
$('input[name=wpcf-menge]').change(compute);
$('input[name=wpcf-produktpreis]').change(compute);
function compute() {
if ( $('input[name=wpcf-produktpreis]').val() != undefined ) {
var a = $('input[name=wpcf-menge]').val();
var b = $('input[name=wpcf-produktpreis]').val();
var gesamtpreis = a * b;
$('input[name=wpcf-gesamtpreis]').val(gesamtpreis);
}
}
} );
Can you please share the problem URL where you added the form as well as access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
many apologies for the delay. I can't share the credentials with you, before my boss approved it. Unfortunatelly I am still waiting for his approval. I will notify you as soon as I have the approval. I am truely sorry for the delay.
many thanks for your help. While I was unwell my work collegue figured out, that we accidently inserted the form two times on the same page. So we had two "Gesamtpreis custom fields" on the page and the JavaScript didn't knew where it should output the results. This caused the issue. After my work collegue removed one of the forms, the remaining form started to work perfectly.
For everyone who wants to calculate something with CRED on the fly, I can really recommend this JavaScript snipplet.