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

Javascript in form treating 0 as null vaues

hina.pdfuser
Registered: Oct 28 2010
Posts: 26

I have form which has some mandatory fields. I have written a javascript which loops all controls and check for null or blank values. But the problem is that it is treating zero also as null. Suppose i write zero in No. Of children textbox, then it should accept that as a value instead it asks user to fill in that field.
 
Here is my code, pls help:
 
var requiredFields = new Array();
for (var i = 0; i < this.numFields; i++)
{
var fName = this.getNthFieldName(i);
var f = this.getField(fName);
if ((f.type=="text" && this.getField(fName).required && (this.getField(fName).value == null || this.getField(fName).value == '' || this.getField(fName).value == '0')) || (f.type=="radiobutton" && this.getField(fName).required && (this.getField(fName).value == "Off")) || (f.type=="checkbox" && this.getField(fName).required && (this.getField(fName).value == "Off")))
{
requiredFields[requiredFields.length] = fName;}}
var error = "Please complete the following fields: \n\n";
for (j=0; j < requiredFields.length; j++)
{
if (requiredFields[j].value == null)
{
error = error + requiredFields[j] + '\n';
var f2 = this.getField(requiredFields[j]);
f2.setFocus();
}

}

 
if (requiredFields.length > 0)
app.alert(error);
else
{
this.submitForm({cURL: "www.abc.com", cSubmitAs: "HTML"})
}

Thanks,
Hina

My Product Information:
Acrobat Pro 9.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
A null field when interpreted as a number value is zero. You should us the 'valueAsString' property when testing for a zero or null value.

George Kaiser