Use a check box to reset a text box and make it read only.

I'm creating a form with two combo boxes and a check box, the user selects from the drop down list of the two combo boxes. I have a check box for N/A when checked will reset the two combo boxes, I'd also like when the check box is checked the two combo boxes are read only, subsequently when its unchecked I need them fill-able again.


Jeff Jarvis


3 Answers

Voted Best Answer

Open up the preferences for your checkbox and select the Actions tab, then select to execute a JavaScript on Mouse-Up. Use something like this to reset the form fields, and make them read-only or read-write. Just keep in mind that you need to use the names of your dropdown fields, and not the names I am using:

if (event.target.value == "Yes")
{
this.resetForm( [ "Dropdown1", "Dropdown2" ] );
this.getField("Dropdown1").readonly = true;
this.getField("Dropdown2").readonly = true;
}
else
{
this.getField("Dropdown1").readonly = false;
this.getField("Dropdown2").readonly = false;
}


By Karl Heinz Kremer   

The best place to put such code is on the MouseUp event of the check box.

Something like this:

if(event.target.isBoxChecked(0))
{
this.getField("MyCombo1").readonly = true;
this.getField("MyCombo2").readonly = true;
this.resetForm(["MyCombo1","MyCombo2"]);
}
else
{
this.getField("MyCombo1").readonly = false;
this.getField("MyCombo2").readonly = false;
}


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


Thom Parker   

Thank you gentlemen, both scripts work fine.


Jeff Jarvis   


Please specify a reason: