Skip Navigation

[Resolved] Calculate the checksum including 10 as an result

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2090561

Tell us what you are trying to do?

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)

#2091193

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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/