Reputation: 1
I have this case:
There is a numeric field, which must be filled with 10 numbered ID of the user. I need to have autamatic check of the existance of that ID. The formula is: [(p1 * 2) + (p2 * 4) + (p3 * 8) + (p4 * 5) + (p5) * 10) + (p6) * 9) + (p7 * 7) + (p8) * 3) + (p9 * 6)] % 11 = p10 where p1 is the first digit, p2 is the second etc.
I am new in javascript, so will be very thankfull for your help. Here is what I've tried:
if ((((this.position(1) * 2) + (this.position(2) * 4) + (this.position(3) * 8) + (this.position(4) * 5) + (this.position(5) * 10) + (this.position(6) * 9) + (this.position(7) * 7) + (this.position(8) * 3) + (this.position(9) * 6)) % 11) == this.position(10))
{
}
else
{
xfa.host.messageBox("Wrong ID", "ERROR!", 1, 0);
}
Upvotes: 0
Views: 381
Reputation: 396
something like this will work:
var s = this.rawValue;
var prod = s.substr(0,1)*2 + s.substr(1,1)*4 + s.substr(2,1)*8 +...
if (prod%11 == s.substr(9,1)){
//do whatever
}
else {
//do whatever else
}
remember that the substr() function starts at 0 instead of 1, and the second 1 makes sure you only take one character.
Upvotes: 1