Skip to main content
Participant
Mar 12, 2019 1:21 AM UTC
Question

lock dropdown menu once a selection is made

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?

This topic is closed to new replies. Start a new post to keep the conversation going.

8 replies

Thom Parker
Community Expert
Community Expert
Mar 12, 2019 3:51 AM UTC

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?

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
More2DoAuthor
Participant
Mar 12, 2019 12:32 PM UTC

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;

Translate
Thom Parker
Community Expert
Community Expert
Mar 12, 2019 4:29 PM UTC

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.

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often