These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Auto tabbing not working, why?

NancyM
Registered: Sep 25 2006
Posts: 40

I am not sure as to why the auto advance is not working in the following script. The alert box does appear when a letter is entered in to the field after tabbing out. Also, the field is cleared and focus is in the right field, but when 3 numeric digits are entered it does not advance. I do not have anything on the Object

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Please re-post script

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

NancyM
Registered: Sep 25 2006
Posts: 40
Here is the script
----- SetupForm.ServiceAuthPage1.Phone2::exit - (JavaScript, client) --------------

if (xfa.event.newText.length == 3)

{
var r = new RegExp("^[0-9]+[0-9]+[0-9]");

var result = r.test(this.rawValue);

if (result == true)
{
xfa.host.setFocus("Phone3");
}
else if (result == false)
{
app.alert("Please enter a valid area code.");
Phone2.rawValue = null
xfa.host.setFocus("Phone2");
}
}
NancyM
Registered: Sep 25 2006
Posts: 40
Here is the script
----- SetupForm.ServiceAuthPage1.Phone2::exit - (JavaScript, client) --------------

if (xfa.event.newText.length == 3)

{
var r = new RegExp("^[0-9]+[0-9]+[0-9]");

var result = r.test(this.rawValue);

if (result == true)
{
xfa.host.setFocus("Phone3");
}
else if (result == false)
{
app.alert("Please enter a valid area code.");
Phone2.rawValue = null
xfa.host.setFocus("Phone2");
}
}
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, first off, because the script is on the "exit" event it is only activated when the user puts the keyboard focus somewhere else. This is what you want for the negative test, but not for the positive test. Break this into two scripts, one for the change event, and one for the validate event.

Also, your regular expression matches 3 or more digits. You might want to change this to match exactly 3 digits.

EX: var myReg = /^\d{3}$/;

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

NancyM
Registered: Sep 25 2006
Posts: 40
I have changed the script as you said. This is what I have now.

----- TaxSetupForm.TaxFilingServiceAuthPage1.Phone1::validate - (JavaScript, client) ------------

var r = /^\d{3}$/;
var result = r.test(Phone1.rawValue);
if (result == false);
{
app.alert("Field is numeric only.");
xfa.host.setFocus("Phone1");
}

----- TaxSetupForm.TaxFilingServiceAuthPage1.Phone1::change - (JavaScript, client) --------------

if (xfa.event.newText.length == 3)
{
xfa.host.setFocus("Phone2");
}

When I click on the PDF Preview tab I receive the following warning.

Script failed (language is javascript; context is xfa[0].form[0].TaxSetupForm[0].TaxFilingServiceAuthPage1[0].Phone1[0])
script=var r = /^\d{3}$/;
var result = r.test(Phone1.rawValue);
if (result == false);
{
app.alert("Field is numeric only.");
xfa.host.setFocus("Phone1");
}
Error: app is undefined

I am getting the alert box "Field is numeric only" before the form opens. Then when I test the field the alert box appears no matter what was entered (all numeric or containing an alpha value). One thing I did notice is if I key an all numeric value again the validation seems to be working and the auto tab works.

Any insite as to what I am doing wrong.