Copy link to clipboard
Copied
Hey all,
I'm trying to create a form that requires information from 1 page and filters it to the next. I want the user to be able to lock the information with a button but also be unlock the information if they need to change something with the same button. I can do it with 2 buttons, but for easier use I would like, if possible, to use 1 button for both functions. Thanky you in advance.
Copy link to clipboard
Copied
Use a checkbox. Here is some sample code for makeing fields read only based on the checked/unchecked state of the checkbox,
MouseUp "Run a JavaScript" action
if(event.target.value == "Off")
{// Unlock field when unchecked
this.getField("SomeField").readOnly = false;
}
else
{// Lock Field when checked
this.getField("SomeField").readOnly = true;
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi,
How are you locking the fields? if you are using the read-only property you could just assign it to the other on button click
something like
var f = this.getField("myTextField");
f.readonly = !f.readOnly;
This would swap the setting each time the button is clicked.
Regards
Malcolm
Copy link to clipboard
Copied
Use a checkbox. Here is some sample code for makeing fields read only based on the checked/unchecked state of the checkbox,
MouseUp "Run a JavaScript" action
if(event.target.value == "Off")
{// Unlock field when unchecked
this.getField("SomeField").readOnly = false;
}
else
{// Lock Field when checked
this.getField("SomeField").readOnly = true;
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Thank you very much! This is an easier fix than two buttons that switch visibility.
Copy link to clipboard
Copied
This code makes perfect sense to do what I'm trying to do but for some reason it doesn't work on my form. Would anyone be able to look at this and see where I'm going wrong? I have a checkbox and when ticked I want to make the fields read-only and/or locked. These four fields repeat throughout the form though, wonder if that's the problem. I tried the fields with the notation as it appears on the form (e.g., Centre ID#0 etc) but that doesn't work either. Can anyone help?
if(event.target.value=="Off") {
this.getField("Centre ID").readOnly = false;
this.getField("Study ID").readOnly = false;
this.getField("Baseline Date").readOnly = false;
this.getField("Baseline Assessor").readOnly = false;
}
else
{
this.getField("Centre ID").readOnly = true;
this.getField("Study ID").readOnly = true;
this.getField("Baseline Date").readOnly = true;
this.getField("Baseline Assessor").readOnly = true;
}
Copy link to clipboard
Copied
Look in the console window to see if any errors are reported.
There is a video on using the console window here:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
There's an error in that code. The name of the property for fields is "readonly". Confusingly, it's "readOnly" for annotations, but not for fields.
Copy link to clipboard
Copied
Ahhhh! That one always gets me. It's "readOnly" for annotations and "readonly" for fields.
Thank Gilad, good catch.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Happens to the best of us! 🙂
Copy link to clipboard
Copied
Oh I see! I learn so much here. Thank you both! It is working like a dream now 🙂

