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

Set fields read only with javascript

New Here ,
Nov 16, 2021 Nov 16, 2021

Hi there! 

I'm having problem using javascript to make read-only a fillable pdf.


I always used this script:
var r = app.alert("Sei sicuro di voler bloccare il PDF?",2,2);
if (r == 4) { // 4 is Yes, 3 is No
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
this.getField(fname).readonly = true; // makes all fields readonly }
}

 

but ultimately it won't work, sometimes all form fields remain editable, sometimes some are ready-only and some are not.

 

Since I'm not a java expert, is there any way to make it work again? 
Thanks!

 

TOPICS
Create PDFs , JavaScript , PDF forms
831
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 ,
Nov 16, 2021 Nov 16, 2021

See if this will work:

var r = app.alert("Sei sicuro di voler bloccare il PDF?",2,2);
if (r == 4) {
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
f.readonly = true;
}}

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 ,
Nov 16, 2021 Nov 16, 2021
LATEST

Thanks for the suggestion!

this script partially works, all fields are read-only apart from one 😞

see attached screenshot.

 

What could the problem be?

 

Thanks again!

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