Expand my Community achievements bar.

SOLVED

Numeric Field Even Numbers Only - No Odd Numbers

Avatar

Level 4

Hello,

 

I need a script on the Exit Event of a Numeric Field which tests that the number entered is Even. If odd, the field is nulled and set to focus.

I only need a way to test if the last character is : 0, 2,4,6 or 8 since that would be even but the number cannot be zero.

The number may be up to 6 numerals.

 

Thank you in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 4

@Gpraveen This worked for me:

 

var x = this.rawValue;
if (x%2==1 || x==0){
this.rawValue = "";
xfa.host.setFocus(NumFields);
}

 

Thank you for the direction from your script.

View solution in original post

3 Replies

Avatar

Level 1

Try this script to check the number is not zero and it it even.

 

function checkEven(x){
    return x!=0 && x%2==0;
}

Avatar

Level 4

I should have mentioned that this is for an XDP Adobe Form. If this is to appear onExit of the field in question, and, the field in question is a numeric field. Then, with these conditions, it does not work. OnExit the field keeps the odd number [in this case "3"] and no further actions happen with respect to the check on even numbers. It does not blank out  the field value and focus back to it, and, onExit the odd number stays and another script triggers to create table rows. So, I appreciate the effort, however, if I am doing something wrong please point it out to me. Thank you.

Avatar

Correct answer by
Level 4

@Gpraveen This worked for me:

 

var x = this.rawValue;
if (x%2==1 || x==0){
this.rawValue = "";
xfa.host.setFocus(NumFields);
}

 

Thank you for the direction from your script.