Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Senior needs help with JavaScript
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Senior needs help with JavaScript

 Post Reply Post Reply
Author
CalamityJane View Drop Down
New Member
New Member


Joined: 10 Sep 2017
Location: Germany
Points: 2
Post Options Post Options   Quote CalamityJane Quote  Post ReplyReply Direct Link To This Post Topic: Senior needs help with JavaScript
    Posted: 10 Sep 2017 at 8:51pm
Hi folks!

here's a piece of code that I'm trying to get it run in a acrobat form. When clicked on a button (called "check iban" - brilliant!) it checks if the iban is valid or not.

First part, code checks, if IBAN has a valid length. Until here the code works.
Second part checks the iban with a modulo calculation. For that, the IBAN string must be reorganised so that it's length can be up to around 40 digits  - too big for modulo.
So for modulo it is necessary to calc in steps.

If I click the check-button, nothing happens - as if not clicked. Somewhere must be a bug and I can not find it. Need your help! Cry


var ibannumstr = this.getfield("IBAN").valueasstring;
var ibanswap = "";
retwert = 0;

var CODE_LENGTHS = {
AD: 24, AE: 23, AT: 20, AZ: 28, BA: 20, BE: 16, BG: 22, BH: 22, BR: 29,
CH: 21, CR: 21, CY: 28, CZ: 24, DE: 22, DK: 18, DO: 28, EE: 20, ES: 24,
FI: 18, FO: 18, FR: 27, GB: 22, GI: 23, GL: 18, GR: 27, GT: 28, HR: 21,
HU: 28, IE: 22, IL: 23, IS: 26, IT: 27, JO: 30, KW: 30, KZ: 20, LB: 28,
LI: 21, LT: 20, LU: 20, LV: 21, MC: 27, MD: 24, ME: 22, MK: 19, MR: 27,
MT: 31, MU: 30, NL: 18, NO: 15, PK: 24, PL: 28, PS: 29, PT: 25, QA: 29,
RO: 24, RS: 22, SA: 24, SE: 24, SI: 19, SK: 24, SM: 27, TN: 24, TR: 26};

var iban = ibannumstr.toUpperCase().replace(/[^A-Z0-9]/g, '');
var code = iban.match(/^([A-Z]{2})(\d{2})([A-Z\d]+)$/);
var digits = "";

if (!code || iban.length !== CODE_LENGTHS[code[1]]) {
   retwert = 0;
} else {

// ****** Code works well until "else" . Here starts the trouble somewhere ****** //

   ibanswap = ibannumstr.substr(4) + ibannumstr.substr(0,4);
   // takes the first 4 chars and put them to the end of the string - no change in string length allowed //



   var i = 0;
   var n = 0;
   for (i = 0; i <= ibanswap.length; i++) {
      if (ibanswap.charAt(i).toUppercase() != ibanswap.charAt(i).toLowercase()) {
      n = ibanswap.charcodeat(i) - 55;
      digits += n.toString();
      } else {
      digits += ibanswap.charAt(i);
      }
   }
   // checking string char by char if a char is a letter or a number.//
   // If letter, get the ascii-code, subtract 55, add it as a string to the digits-string //
   // If number, add it as a string to the digits-string //



   while (digits.length > 8) {
      n = parsefloat(digits.substr(0,4)) % 97;
      digits = digits.substr.(4);
      if (n > 0 ) {
         digits = n.toString() + digits;
      }
   }
   // digits can be up to 50 chars long. To get a modulo operation, we have to do it in steps.//
   // step 1: get the first 4 chars, turn it into a number, calculate modulo //
   // step 2: remove the first 4 chars in digits-string //
   // step 3: if modulo-calc returns <> 0, put the result as a string in front of the digits-string //
   // goto step 1 until length is < 8 // 


   n = parsefloat(digits) % 97;
   if (n = 1){
      retwert = 1;
   } else {
      retwert = 0;
   }
  // modulo-calc with the rest of the string which can be up to 8 chars //
  // if result is 1, iban number is valid, if <> 1, not valid //
}

source:
code from here: /stackoverflow. com/questions/21928083/iban-validation-check
changes made to get it run in Acrobat - not yet successful

The End is near
Back to Top
Sponsored Links


Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1093
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 2017 at 8:26am
Use:
   if (n == 1){
      retwert = 1;
   } else {
      retwert = 0;
   }

not:
   if (n = 1){
      retwert = 1;
   } else {
      retwert = 0;
   }
Back to Top
CalamityJane View Drop Down
New Member
New Member


Joined: 10 Sep 2017
Location: Germany
Points: 2
Post Options Post Options   Quote CalamityJane Quote  Post ReplyReply Direct Link To This Post Posted: 11 Sep 2017 at 6:38pm
Hi BAlheit,

many thanks but this was not the "big" bug. I changed to code but it doesn't get better with it. It's still nochtinh happend when clicked.

By the way. That button checks a lot of other things, too. For example if strings exist for name and surname, address, phone number, bank details, and so on.

Is there a maximum length for a code that can be run within a acrobat button?

 
The End is near
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.014 seconds.