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

check ckeckbox status

Nandiny
Registered: Jul 23 2009
Posts: 6

Hello,

Here is my Problem. I want to create 20 checkboxes in acrobat with the following condition: if 5 of 20 chechboxes are checked, it shouldn't be possible to check another one.
I have no idea which command I have to use for the checkboxes. My Code so far:

var f = this.getField("control");
var g = this.getField("control2");

if (f == checked) // i don't know the right command
g.checkThisBox(0,false);

Maybe someone can help me.

Thanks Nandiny

My Product Information:
Acrobat Standard 8.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
JavaScript is an object orienttated scripting language, so one needs to not only access the object but will also need to access a property of the object or use a method of the object to process the desired object.

So to test the value of the 'control' field, one needs to access the value of the field or other property.
var f = this.getField('control'); // get the 'control' object// report the value of the fieldvar sMsg = '\'control\' has the following value: ' + f.value;sMsg = sMsg + '\n' + '\'cotrol\' isBoxChecked has a value of: ' + f.isBoxChecked(0);sMsg = sMsg + '\n' + '\'cotrol\' isBoxChecked has a logicl value of: ' + (f.isBoxChecked(0) == true)app.alert(sMsg, 3, 0);// report if the field is checkedif(f.isBoxChecked(0) == true)app.alert('\'control\' is checked', 3, 0);elseapp.alert('\'control\' is not checked', 3, 0);

George Kaiser

Nandiny
Registered: Jul 23 2009
Posts: 6
Great thank you. So far so good :)


My aim is, if 4 checkboxes are checked no other checkbox could be checked.
Now I've tried to go on with the following code:

var count = 1;
var myArray = new Array("control", "control2", "control3", "control4", "control5", "control6", "control7");

for( i = 0; i < 7; i++ ) {
if(myArray[i].isBoxChecked(0) == true){
count = i + count;
if (count>4){
myArray[i].checkThisBox(0,false);
}
}
}

But it doesn't work. Does anyone has an idea?

Nandiny
Nandiny
Registered: Jul 23 2009
Posts: 6
I found my problem, the array declaration wasn't correctly.

var myArray = new Array();
myArray[0] = this.getField('control');
myArray[1] = this.getField('control2');
....

This is how it works.