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 EDIT form.
I am using the JavaScript:
jQuery( function( $ ) {
$('input[name=menge]').change(compute);
$('input[name=produktpreis]').change(compute);
function compute() {
var a = $('input[name=menge]').val();
var b = $('input[name=produktpreis]').val();
var gesamtpreis = a * b;
$('input[name=gesamtpreis]').val(gesamtpreis);
}
} );
It works awesome as long as I use the javascript code on a single page. As soon as I use it inside a view loop, it will start to use for "var a" and "var b" the values of the custom fields in the first loop item. Is there a way, that I can give the custom fields a loop index or a post ID. For example like name=menge_loop-number. I did search for something like that here in the support forum, but I couldn't find a hint or an idea.. how can this be approached in the best way.
Is there any documentation that you are following?
https://toolset.com/forums/topic/multiply-two-custom-fields-cred-form/
Is there a similar example that we can see?
no
What is the link to your site?
versteckter Link
This code, in fact, will always look for the first inputs that match the selectors 'input[name=menge]' and 'input[name=produktpreis]'.
The compute function needs to be adapted to look for the input in the same form. The following code may work for you, I did not test it:
function compute() {
var form = jQuery(this).closest("form");
var a = form.find('input[name=menge]').val();
var b = form.find('input[name=produktpreis]').val();
var gesamtpreis = a * b;
form.find('input[name=gesamtpreis]').val(gesamtpreis);
}
If this code does not work for you, please allow me temporary access to your site and let me check it closely, I'll need to know what form and what view are involved. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
My issue is resolved now. Thank you!