Copy link to clipboard
Copied
Hoping someone can help me with a specific requirement I have. I have included an action button in my pdf to make certain fields in my form read only. I have written the javascript code for it and it works perfectly. I need to include a second action button that would reverse the 'read-only' fields back to being eidtable but this second button should be executed only on a successful password entry. Can someone please help with the javascript code that is required for this second button?
Thank you!
Copy link to clipboard
Copied
Try this script (don't forget to set the password and the name of the field to be unlocked):
var cResponse = app.response({cQuestion: "Enter password", cTitle: "PASSWORD", });
{
// Cancel
if (cResponse == null) {app.alert({cMsg: "You must enter your password to unlock this field.", cTitle: "PASSWORD", nIcon: 3});}
// password OK
else if (cResponse == "123456") {this.getField("lockedField").readonly = false;}
// password KO
else {app.alert({cMsg: "Invalid password.", cTitle: "PASSWORD", nIcon: 0});}
}
Acrobate du PDF, InDesigner et Photoshopographe
Copy link to clipboard
Copied
Try this script (don't forget to set the password and the name of the field to be unlocked):
var cResponse = app.response({cQuestion: "Enter password", cTitle: "PASSWORD", });
{
// Cancel
if (cResponse == null) {app.alert({cMsg: "You must enter your password to unlock this field.", cTitle: "PASSWORD", nIcon: 3});}
// password OK
else if (cResponse == "123456") {this.getField("lockedField").readonly = false;}
// password KO
else {app.alert({cMsg: "Invalid password.", cTitle: "PASSWORD", nIcon: 0});}
}
Acrobate du PDF, InDesigner et Photoshopographe
Copy link to clipboard
Copied
@JR Boulay Thank you! It worked perfectly! 🙂
Copy link to clipboard
Copied
Keep in mind that this is a very low security level since the password is stored in the script.
Acrobate du PDF, InDesigner et Photoshopographe
Copy link to clipboard
Copied
What if I want to unlock multiple fields with the password? What’s the syntax for that? Something like this, perhaps?
var cResponse = app.response({cQuestion: "Enter the password", cTitle: "PASSWORD", });
{
// Cancel
if (cResponse == null) {app.alert({cMsg: "You must enter your password to unlock these fields.", cTitle: "PASSWORD", nIcon: 3});}
// if password is correct
else if (cResponse == "123456") {
this.getField("LockedField1").readonly = false;
this.getField("LockedField2").readonly = false;
this.getField("LockedField3").readonly = false;
}
// if password is incorrect
else {app.alert({cMsg: "Invalid password.", cTitle: "PASSWORD", nIcon: 0});}
}
Copy link to clipboard
Copied
Hi @joseph_2523,
Hope you are doing well. Thanks for writing in!
If you are still looking for a solution, here is my take on it:
var cResponse = app.response({
cQuestion: "Enter the password",
cTitle: "PASSWORD"
});
// Cancel
if (cResponse == null) {
app.alert({
cMsg: "You must enter your password to unlock these fields.",
cTitle: "PASSWORD",
nIcon: 3
});
}
// If password is correct
else if (cResponse == "123456") {
this.getField("LockedField1").readonly = false;
this.getField("LockedField2").readonly = false;
this.getField("LockedField3").readonly = false;
app.alert({
cMsg: "Fields unlocked successfully.",
cTitle: "SUCCESS",
nIcon: 1
});
}
// If password is incorrect
else {
app.alert({
cMsg: "Invalid password.",
cTitle: "PASSWORD",
nIcon: 0
});
}
Please note that I am no expert when it comes to java scripting. This is just a try which might or might not work.
Regards,
Souvik.
Copy link to clipboard
Copied
If you don't want the password to be human-readable, you can use Unicode to encode it, for example for “123456” :
else if (cResponse == "\u0031\u0032\u0033\u0034\u0035\u0036") {
You can use this free tool to Uni-encode the string:
https://www.abracadabrapdf.net/utilitaires/utilitaires-pdf/texte-vers-unicode/
But bear in mind that this is not an absolute protection, it's just an additional difficulty for anyone who wants to know the password by analyzing the code.
Acrobate du PDF, InDesigner et Photoshopographe

