Ok, I'll add my 2 cents. My impression is that you want this functionality
- Checkbox "On" - User can enter data into the field
- Checkbox "Off" - Field cleared and user is unable to enter data.
The easy code is what Max provided, use the check box Mouse Up to set the ReadOnly property of the field and to clear it when necessary. But this does not provide a general solution. There are still situations where the field can filled, and/or the check box changed that do not trigger the correct behavior.
The complete solution is to use either a calculation script on the field or the "Keystroke/WillCommit" script on the check box, because these events are activated in all situations. Unfortunately its a pain to enter a keystroke script into a checkbox, so the calculation script on the text box is the winner.
Here is a correction of Almir's script:
// In text field
if(this.getField("Check1").value == "Off")
{
event.value = "";
event.target.readonly = true;
}
else
event.target.readonly = false;
It is important to always set the field value with "event.value" in a calculation.
Now, here is a much simpler and trickier script that does the same thing
event.rc = (this.getField("Check1").value == "Off");
event.target.readonly = event.rc;
event.value = "";
Thom Parker
The source for PDF Scripting Info pdfscripting.com
All About PDF Stamps in Acrobat and Paperless Workflows - THE BOOK !!
The Acrobat JavaScript Reference, Use it Early and Often
The most important JavaScript Development tool in Acrobat
The Console Window (Video tutorial)
The Console Window(article)
Having trouble, Why Doesn't my Script Work