I have some code that works about like I want with one small glitch. The alert works when the character count in incorrect, and it keeps focus on the field. The problem is that after the correct number of characters are entered in the field, it still keeps focus on the field until you tab out of it.
I need it to work like it does, with the exception that when the correct number of characters is entered, it needs to go to the next field automatically.
If the alert is removed, it works correctly, except, of course, I do not get the alert. Here is my code.
var r = new RegExp();
r.compile("^([0-9]{8})$","i");
var result = r.test(this.rawValue);
if (result == true)
true;
else
app.alert("SAP numbers are 8 digits. Please re-enter the SAP number.", 0);
xfa.host.setFocus(this);
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
You need to add braces to the else. Without braces it only executes the first statement so setFocus always executes. As a habit I use braces on all if-else statements.
if (result == true) {
true;
}
else {
app.alert("SAP numbers are 8 digits. Please re-enter the SAP number.", 0);
xfa.host.setFocus(this);
}
Steve
Views
Replies
Total Likes
You need to add braces to the else. Without braces it only executes the first statement so setFocus always executes. As a habit I use braces on all if-else statements.
if (result == true) {
true;
}
else {
app.alert("SAP numbers are 8 digits. Please re-enter the SAP number.", 0);
xfa.host.setFocus(this);
}
Steve
Views
Replies
Total Likes
That did it. Sometimes it is just something that simple. I thought I had tried it with the brackets, but I guess I didn't. Thanks
Views
Replies
Total Likes