Skip Navigation

[Resolved] Calculate the checksum

This thread is resolved. Here is a description of the problem and solution.

Problem:
Calculate the checksum

Solution:
You will require write the custom javascript code to calculate the checksum of given number.

You can find proposed solution in this case with the following reply:
https://toolset.com/forums/topic/calculate-the-checksum/#post-2070775

Relevant Documentation:

This support ticket is created 3 years, 8 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 3 replies, has 2 voices.

Last updated by Jennifer 3 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#2069915
checksum-problem.jpg

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: 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.

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?
hidden link (But you have to register to see the fields)

#2070017

Minesh
Supporter

Languages: English (English )

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

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.

#2070775

Minesh
Supporter

Languages: English (English )

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

Can you please check now.

I've adjusted the JS code you added as given under:

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-materialzahl']").val(round2_res);
    
          
}
     
} );

I can see the expected results now. Can you please confirm it works at your end as well.

#2070865

My issue is resolved now. Thank you!