Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Enabling action button on password

New Here ,
May 04, 2022 May 04, 2022

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!

TOPICS
How to , JavaScript , PDF forms
623
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
May 04, 2022 May 04, 2022

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

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2022 May 04, 2022

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 04, 2022 May 04, 2022

@JR Boulay Thank you! It worked perfectly! 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2022 May 04, 2022

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 06, 2025 Feb 06, 2025

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});}
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 11, 2025 Mar 11, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 11, 2025 Mar 11, 2025
LATEST

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines