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

Display alert based on failure to select checkbox

rbr00x
Registered: Oct 14 2009
Posts: 26
Answered

Acrobat Professional 9.2.0
 
I am trying to display a message when the user fails to select a checkbox. The code is working, but it is doing the opposite of what I want. It only displays the message when the checkbox is selected.
 
I have a group of 3 checkboxes named payment_option and I have set the export values to 1, 2, and 3. I guess I don't understand how the isBoxChecked works.
 
Here is the code...
  
if (this.getField("payment_option").isBoxChecked(0))
{
app.alert("You have not chosen a payment option. Please choose a payment option before submitting this form.", 3, 0, "Form Completion Instructions");
}
 
I appreciate any help!

My Product Information:
Acrobat Pro 9.2, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Change the first line of the code to this:

if (this.getField("payment_option").isBoxChecked(0)==false)

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

rbr00x
Registered: Oct 14 2009
Posts: 26
OK that corrects if for the first checkbox but the other two still display the message when checked.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
I would test the value of the check box not being equal to 'Off'.

if (this.getField("payment_option").value == 'Off')
{
app.alert("You have not chosen a payment option. Please choose a payment option before submitting this form.", 3, 0, "Form Completion Instructions");
}The "(0)" references the first created widget of the check box group with the same name and not the entire group of check boxes with the same name.

If you want to use the 'isBoxChecked' method you need to test each widget for not being checked:

if (!(this.getField("payment_option").isBoxChecked(0)) & !(this.getField("payment_option").isBoxChecked(1)) & !(this.getField("payment_option").isBoxChecked(2)) )
{
app.alert("You have not chosen a payment option. Please choose a payment option before submitting this form.", 3, 0, "Form Completion Instructions");
}

George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
If you want to display the message if none of them is selected, use this:

if (this.getField("payment_option").isBoxChecked(0) == false && this.getField("payment_option").isBoxChecked(1) == false && this.getField("payment_option").isBoxChecked(2) == false)By the way, why are you using check-boxes and not radio-buttons for this?

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

rbr00x
Registered: Oct 14 2009
Posts: 26
Well I guess I am using checkboxes intead of radio buttons out of habit - no valid reason! I can change it if that makes the form more efficient.
rbr00x
Registered: Oct 14 2009
Posts: 26
I did not see the post from George Kaiser - that method also works. Thank you!
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Checking the value of the group does not require editing the script if check boxes are added or removed.

Both Check Boxes and Radio Buttons have a value of 'Off' with there is not selection made. Also the 'isBoxChecked' works the same for the check boxes and radio buttons.

George Kaiser