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

Javascript questions for form fields

tyler1
Registered: Dec 16 2008
Posts: 9
Answered

Hey guys, I've been reading these forums for a while, and they have been awesome at helping me to find answers to my questions up until now. I'm getting to the point where I have questions that I don't think have been previously asked!

So, I'm making a form for my work which will be a way of filling out data online. I'm using existing PDFs that I am just adding form fields to. The way it needs to be set up is: I have 6 checkboxes set up on line 1 of the form operating as radio buttons so they are mutually exclusive. The user can only select one of the 6 checkboxes and depending on which they select, different fields appear/hide on the lines below that. I have all that functionality working. Javascripts tied to the 6 checkboxe's 'Mouse Up' events control the display/hiding of all the other fields depending on which checkbox has been selected.

But now I have just been informed that the checkboxes not only need to be mutually exclusive, they also need to be deselectable. I set up this functionality using a global variable to store the old value of the checkbox, and when the user clicks on another checkbox it compares the new value of the checkbox with the old value. If they are the same, it uses a this.getField("foo").value = "Off" code to deselect the check box. This correctly makes the checkboxes deselectable while still being mutually exclusive.

The only problem with this is that the fields on the lines below do have their display value modified, because a mouse up event has not been triggered by changing the value. I need to make these other fields always change depending on which checkbox is selected on line one, or hide all of them if no checkbox has been selected.

Could I use the global variable subscribe function to do this? Or is there a way to make radio buttons deselectable while still mutually exclusive? I don't mind rewriting code to replace what I already have, but I do have the requirement that this form needs to run fast, so I want to make optimal javascript. Any ideas about the right way to approach this?

Thanks in advance!
-Tyler

My Product Information:
Acrobat Pro 8.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
If you use check boxes, and give each in the group the same name but different export value, they will be mutually exclusive and you will be able to deselect one so that none in the group is selected. No scripting is required for this.

In the Mouse Up event of each check box you would place code to reset and activate/deactivate the other fields associated with the check box group.

I don't see a need for using global variables for any of this.

George
tyler1
Registered: Dec 16 2008
Posts: 9
The checkboxes do have the same name with different export values, which I understand makes them mutually exclusive like radio buttons. For example, I have 2 fields that are checkboxes. When I go to the 'Properties' option of the fields, under the 'General' tab for both checkboxes I have them named 'Book' and under the 'Options' tab I have the export value for one as "FI" and the export value for the other as "CB".

However, once one has been selected, I can not deselect that one by clicking again on the same checkbox. I can change my selection to one of the other checkboxes with the same name (but different export value), but I am still forced to choose one of the checkboxes. I can not seem to make it deselect any of the options once one has been selected.

I believe I have my checkboxes set as you are describing it. Is there perhaps some option for the PDF itself I need to change? I'm using version 8.1 pro on a Macintosh.
tyler1
Registered: Dec 16 2008
Posts: 9
Actually, it seems that even though they are showing up as checkboxes, when I right click on them and select 'Properties' the title of the properties box is "Radio Button Properties" so I guess at some point these got turned into radio buttons somehow. When I delete them and recreate them as checkboxes, this does not happen. Thanks for the reply George, I need to look closer at what is going on!