Mandatory field validation infinite loop query...
Hi everybody,
Please can someone help me out.
I've a number of 'mandatory' text fields on a form.
I've setup a 'Document Javascript' that sets the focus to the first mandatory field upon opening the pdf.
Using an onBlur action I'm testing to see if the user has entered something in the first text field.
If they haven't, e.g. they've just tabbed to the next field, they get a popup asking them to fill in the field and then the focus is set back on that field.
If the user only enters a space, and then tabs onto the next field, the text field value is checked to see if that's the case. If it is, the user gets a popup and then the focus is set back to the text field.
If the user enters something other than just spaces they are ok.
The problem I've got is that the form gets stuck in a loop between the action of tabbing to the next field and the onBlur test.
Here's my code.
var fld = this.getField("TextBox1");
var nxtFld = this.getField("TextBox2");
if (fld.value !== "") { //if field is not empty
var emptyTest = /^\s*$/;
if(emptyTest.test(fld.value)) {
app.alert("Only spaces, please enter the relevant information");
fld.value = "";
fld.setFocus();
}
}
else { //if field is empty
app.alert("This field is required.\n\nPlease fill in the Name field2");
fld.setFocus();
}
Hope that makes sense.
Please can someone help.
Thanks in advance.
