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

lock dropdown menu once a selection is made

Explorer ,
Mar 11, 2019 Mar 11, 2019

Copy link to clipboard

Copied

In a PDF form, is there a script that will lock a dropdown menu once a selection is made so that no further changes are possible?

TOPICS
Acrobat SDK and JavaScript

Views

2.2K

Translate

Translate

Report

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, 2019 Mar 11, 2019

Copy link to clipboard

Copied

Yes, Put this script into the Validation script for the dropdown.

event.target.readonly = (event.value.length > 0);

Did you want a way to unlock the field?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Explorer ,
Mar 12, 2019 Mar 12, 2019

Copy link to clipboard

Copied

Hi Thom, thanks for your response. Your script does work, however, I was a bit too brief in my original query. I've created two buttons on my PDF form—one to "lock" all fields and one to "unlock" all fields. I'm using the script below to lock all fields and a slightly modified version to unlock all. This script, however, does not work for the dropdowns. Is there a script I can add to what I already have? Thank you!

if (event.target.value != "Off") { 

this.getField("text").readonly = true; 

} else { 

this.getField("text").readonly = false; 

}

this.getField("Clear").readonly = true;

Votes

Translate

Translate

Report

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 12, 2019 Mar 12, 2019

Copy link to clipboard

Copied

Setting readonly back to false works in my testing. But there is another way. Make one of the dropdown entries a single space, so it looks blank. You could actually make this anything that works for being an unset value. Then change the validation code to use this value as the key for locking the field.

event.target.readonly = (event.value != " ");

Setting the field to this value will unlock it.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Jan 31, 2022 Jan 31, 2022

Copy link to clipboard

Copied

The script works exactly like I needed it to. Can you please share your tip for unlocking the field after you've made a selection in the dropdown and it is readonly?

 

Thanks for your help!

Votes

Translate

Translate

Report

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 ,
Feb 01, 2022 Feb 01, 2022

Copy link to clipboard

Copied

It's in the replies above.  Locking the fields is the same as setting the "readonly" attribute.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

Thom,

 

Could you 'spell out' what scrip to use and how to insert it into a PDF to unlock the dropdown, once we've used your scrip to lock a dropdown?

Thank you.

 

Votes

Translate

Translate

Report

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 ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

Unlocking doesn't requires a script.

 

But if you need the user to be able to unlock it, or you want an automatic method, then a document action of some kind is needed.

One easy way to do a form reset. The form reset action can be added to a button without a script. This will set the field to the blank entry, which will unlock it. 

Another way to do this is to add a button and script to explicitly set the dropdown value to the blank entry. 

  this.getField("Dropdown1").value = " ";

 

Or another method is to set the readOnly property of the dropdown in the button script.

   this.getField("Dropdown1").readonly = false;

 

Which method is used depends on the way in which the form is to be used. Think about that first. 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

LATEST

Ok, thanks.

Votes

Translate

Translate

Report

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