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

Checking one of a group of fields is filled in

adjmcloon
Registered: Jan 8 2010
Posts: 13

Hello,
 
I am working in acrobat, using javascript to try and validate if one out of a group of 4 checkboxes is selected before returning "true" to a variable to mail the pdf.
 
I am not quite sure where to start with this. Here is my code as it sits..it currently checks for required fields, but I am unsure exactly how to look at a grou of fields to make sure at least one is checked.
  
var bSuccess = true;
 
//Populate the subject line with customer and salesperson info
var cSubline = this.getField("Custname").value + " request for inventory, "
+ "Custno: " + this.getField("Custno").value + " "
+ "Salesperson: " + this.getField("Salesman").value;
var msgBody = "Request for inventory form attached.";
var address = "tjoines [at] preciousmetals [dot] com";
 
//Validate required fields
var requiredFields = new Array(3)
requiredFields[0] = "Salesman";
requiredFields[1] = "Custname";
requiredFields[2] = "Custno";
 
var alertMsg = new Array(3)
alertMsg[0] = "Please enter the salesperson code for this order.";
alertMsg[1] = "Please enter the Customer name.";
alertMsg[2] = "Please enter the Customer code from CRM.";
 
var emptyTest = /^\s*$/;
var fieldCount = requiredFields.length
var fld = 0;
 
for (var i=0; i < fieldCount; i++)
{
fld = this.getField(requiredFields[i]);
if( emptyTest.test(fld.value) ) // if required field is empty
{
bSuccess = false;
app.alert(alertMsg[i],1);
fld.setFocus();
break;
}}
 
//Validate Inventory Type checkboxes
   
//Check for validation true or false
if (bSuccess) {
//Send the Order as PDF
this.mailDoc({
bUI: true,
cTo: address,
cSubject: cSubline,
cMsg: msgBody,
cSubmitAs: "PDF"
});
}

My Product Information:
Acrobat Pro 9.4.3, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
The value of a check box is equal to the string "Off" (but not "off", null, false, or anything else) when it is not selected. This also the case if you create a group of check boxes that have the same name. If none in the group is selected, the value is "Off". Get the value of the check box and see if it's equal to "Off", and go from there.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
So basically change this line:
if( emptyTest.test(fld.value) ) // if required field is empty

To this:
if(fld.value=="Off") // if required field is empty

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

adjmcloon
Registered: Jan 8 2010
Posts: 13
Thank you!