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: 86 is the number entered.
The result should be: 86= 8+6= 14=1+4=5
I used a Javascript for that:
jQuery( function( $ ) {
$("input[name='wpcf-geburtdatumzahl1']").change(quersumme);
function quersumme() {
var tmp = $("input[name='wpcf-geburtdatumzahl1']").val().split('');
var quer = 0;
for (var i=0; i < tmp.length; i++) {
quer += Number(tmp[i]);
}
var round2 = quer.toString().split('');
var round2_res = 0;
for (var i=0; i < round2.length; i++) {
round2_res += Number(round2[i]);
}
$("input[name='wpcf-loesungszahl01']").val(round2_res);
}
} );
The code works fine. However, the number 10 should still be included in the output.
For example:
55 is the number entered the checksum should be 10 and not 1
56 is the number entered. the checksum should then be 2 (5+6=11=1+1=1)
I know that I need an if or while condition (quer > 10), but I can't integrate it without breaking the function.
I've tried all sorts of things now. Unfortunately, I am not an expert in JavaScirpt :'(
It would be nice if someone could give me a tip on how to do this.
Thanks a lot.
Best regards
Jenny
What is the link to your site? hidden link (But you have to register to see the fields)
Hello. Thank you for contacting the Toolset support.
Hi Jennifer,
I remember that I shared the code and I updated you that this is pure custom Javascript code which has nothing to do with Toolset. As per our support policy, we are not allowed to support such custom edits.
Its pure custom programming which is beyond the scope of our support policy. If you need custom programming for your project, you are welcome to contact any of our certified partners with the following link:
=> https://toolset.com/contractors/