Ummm...you really only need one simple array. To keep track of which rows are blank/nonblank.
Like this:
Code:
function isBlank( fname )
{
var val = this.getField( fname ).value;
val = val.replace(/^\s+/,"").replace(/\s+$/,""); // trim off leading/trailing spaces
return val == ""; // return true if field was blank
}
function checkQ4a()
{
var allOrNone = this.getField("fds_4anone").value;
isYes = allOrNone == Yes"; // ???? THIS PROBABLY WON'T WORK!
var allBlank = true;
var rowBlank = [ ]; // array
for ( var row = 1; row <= 5; ++row )
{
var threeblank =
isBlank("fds_4aposition" + row)
&& isBlank("fds_4aorganization" + row)
&& isBlank("fds_4aagency" + row);
allBlank &= threeblank;
rowBlank[row] = threeblank;
}
if ( isYes )
{
if ( ! allBlank )
{
return "All fields for this question must be left blank since you checked 'None' as your answer.\n";
}
/* else: NONE and allBlank, so all is okay */
return "";
}
// if we get here, NONE was *NOT* checked, so ...
if ( allBlank )
{
return "You must check 'None' or fill in an answer.\n";
}
var strError = "";
for ( var row = 1; row <= 5; ++row )
{
if ( rowBlank[row] )
{
strError += "All fields in row " + row + "must be filled.\n";
}
}
return strError;
}
If your field
fds_4anone is a check box or a pair of radio buttons, then I don't think you can simply get its value like that. I think you would need to actually test to see what is checked/unchecked. But maybe not, since this is for PDF and not a browser. You will have to figure that part out.
I do think that just testing for a blank/nonblank field is HORRIBLY inadequate. It means that a person could, for example, enter a single period (or single asterisk or ...) for each answer and you would accept it.
Without knowing the kind of data you expect in all those fields, though, I can't do better than the blank test as you were doing it. I did improve it so that it strips off any leading or trailing spaces from the entered value. Which at least means that the user can't just enter a space for the answer.