I have a number field "entered-number" in which the user can enter a number. The checksum ("Quersumme" in german) should then be calculated and displayed in a new field "result"
For example: 567 is the number entered.
The result should be: 567= 5+6+7 = 18 = 1+8 = 9
I used a Javascript for that:
jQuery( function( $ ) {
$("input[name='wpcf-entered-number']").change(quersumme);
function quersumme() {
var tmp = $("input[name='wpcf-entered-number']").val().split('');
var quer = 0;
for (var i=0; i < tmp.length; i++) {
quer += Number(tmp[i]);
}
$("input[name='wpcf-result']").val(quer);
}
} );
The code works so far and also gives me the result in a new field. My only problem is that he checksum should be a single digit number but the code only prints the result 18 and does not continue to calculate the checksum until the number is less than 10.
I've tried a while loop, but I don't know exactly if the code is correct and how I can integrate it into the code above to make it work.
while (tmp > 10) {
tmp = quersumme();
}
I hope you can help me with my problem. That would be great.
Hello. Thank you for contacting the Toolset support.
This is not really a Toolset issue but if you can share what will be the limit of maximum character you will allow to input.
is it three digit number or four digit number?
Also, if you can share problem URL where you added the number field and access details I would be happy to help.
*** 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.