I’m working with Adobe Acrobat 6.0 for Win to render a simple fillable form with text fields and checkboxes. But I’d like to implement very simple programming so that when the user clicks one particular checkbox, another checkbox also turns checked--making the 'pairing' of these items a sort of default. Users then have to “opt out” of the second checkbox (and uncheck the box) if they prefer to not have that collateral option.
Acrobat forms do support a limited form of Javascript. For example, choose the checkbox tool from the forms toolbar, right-click on the first checkbox, choose properties, click the Actions tab, and you can program an action to follow the mouse-up event for the checkbox. After perusing Adobe’s scripting reference materials, the solution probably would be something like:
var f = this.getfield("NameOfCheckbox");
f.checkThisBox(17,true);
(where the second checkbox is the 18th instance of a checkbox in this particular form). But this specific coding, loaded into the action properties of the first checkbox doesn’t work in triggering the checking of the second, and I’m quite sure I’m doing something woefully wrong here. I'm not perfectly sure exactly what the zero-based item number (17 in the example above)--if someone could clarify that, it'd be a welcome bonus.
Has anyone done this very basic (I'd think common) bit of scripting? Can you lead me in the right direction?
Thanks!
Dale Davaz
da...@stcu.org
You can make your "linked" checkbox checked by default, and then set an action on the first checkbox to show/hide the other field when it is checked. That avoids the whole JavaScript issue altogether.
The other option would be to go to the Actions tab of your first checkbox. Select "Mouse up" as the trigger, and "Run a JavaScript" as the action, then click Add.
This will give you the JavaScript editor, where you would put in the command to check the other field.
Of course, you probably want the actual JavaScript.. which I don't know offhand. But that's where you should be putting it! :)
Nathan
If you (or anyone!) has a minute to give me a hand with the actual lines of scripting themselves, I'd sure appreciate it. My strong suspicion is that the checkThisBox method is at the center, but I'm having a devil of a time getting it in just the right form to work. Insights are definitely welcome!
Dale Davaz
da...@daledavaz.com
da...@stcu.org
Nathan
<http://sedonainfotech.com/docc/CheckboxExample.pdf>
Let me know if it worked.
Manu.
>Let me know if it worked
Works beautifully for me (Acrobat 5.0.5, Win2K, IE 6.0).
// declare values for CheckBoxFirst (main) and CheckBoxSecond CheckBoxThird(dependent)
var f = this.getField("CheckBoxFirst");
var g = this.getField("CheckBoxSecond");
var h = this.getField("CheckBoxThird");
// test the field CheckBoxFirst to see if it is checked
if(f.isBoxChecked(0)) // 0 = the box is checked
g.checkThisBox(0,true); // true = check this box
else
g.checkThisBox(0,false); // false = don't check box
if(f.isBoxChecked(0)) // 0 = the box is checked
h.checkThisBox(0,true); // true = check this box
else
h.checkThisBox(0,false); // false = don't check box
Dale Davaz