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

How to write a Javascript code for making a field required conditionally, in a PDF Form?

Community Beginner ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

I have designed an Interactive PDF Form in which the user is required to check 4 boxes eg A,B,C,D. If the user fails to check any of the 4 boxes, comments section has to be come a required field. This will require a Javascript I assume, which i don't know. Please help

Views

1.9K

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

correct answers 2 Correct answers

Community Expert , May 22, 2020 May 22, 2020

As the custom calculation script of the comments field enter the following code:

 

var a = this.getField("A").valueAsString=="Off";
var b = this.getField("B").valueAsString=="Off";
var c = this.getField("C").valueAsString=="Off";
var d = this.getField("D").valueAsString=="Off";

event.target.required = (a || b || c || d);

Votes

Translate

Translate
Community Expert , May 26, 2020 May 26, 2020

Use this code as the custom calculation script of your field:

 

var a = this.getField("group 1").valueAsString=="No";
var b = this.getField("group 2").valueAsString=="No";
var c = this.getField("group 3").valueAsString=="No";

if (a && b && c) event.value = "Thank you...";
else event.value = "Sorry...";

Votes

Translate

Translate
Community Expert ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

Let me move this to the Acrobat forum for you, where you are more likely to receive an answer to your question.

The Community Help forum is for help in using the Adobe Support Community forums, not for help with specific programs. Product questions should be posted in the associated product community.

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 ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

As the custom calculation script of the comments field enter the following code:

 

var a = this.getField("A").valueAsString=="Off";
var b = this.getField("B").valueAsString=="Off";
var c = this.getField("C").valueAsString=="Off";
var d = this.getField("D").valueAsString=="Off";

event.target.required = (a || b || c || d);

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 Beginner ,
May 22, 2020 May 22, 2020

Copy link to clipboard

Copied

You are super awesome. My heartiest thanks to you. The code worked like a charm!! Million 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
Community Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Please help me with one more thing:

I have 3 questions with Yes/No choice. I have created group 1, group 2 and group 3. If the answer for all the 3 is No then i have to display a message " Thank you ......" and if any one is Yes then the display message will be "Sorry ...". How do we display these messages? Thanks in advance!

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Use this code as the custom calculation script of your field:

 

var a = this.getField("group 1").valueAsString=="No";
var b = this.getField("group 2").valueAsString=="No";
var c = this.getField("group 3").valueAsString=="No";

if (a && b && c) event.value = "Thank you...";
else event.value = "Sorry...";

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 Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Thanks for your prompt response. I have only text and choice boxes on the form. Where do I insert the script?

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

As the custom Calculation script of your text field.

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 Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

I inserted a new text field inthe form and added the script to Custom Calculation script but after i select the choices for the groups it does not display the message in the text box. What am i missing? I have made it a read only field. Is it possible to display the message in this text box?

Is it possible that I create 2 test fields and based on the condition above hide/unhide them?

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Hard to say without seeing the file, but the first step should be to check the JS Console (Ctrl+J) for error messages.

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 Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Is it possible that I create 2 text fields and based on the condition above hide/unhide them?

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Yes, but it's not needed.

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

My guess is one of the names of the fields is incorrect, or their export values.

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 Beginner ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

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 ,
May 26, 2020 May 26, 2020

Copy link to clipboard

Copied

Did you check the JS Console, as I've suggested? The problem will be very clear if you do.

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 Beginner ,
May 28, 2020 May 28, 2020

Copy link to clipboard

Copied

Thanks. It worked, saw the error on the console, fixed it. May thanks again!!

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 03, 2023 Jan 03, 2023

Copy link to clipboard

Copied

LATEST

I would like a text box where numbers are entered and if a certain number is entered, a specific hidden Template will populate.  Can you please help me with the coding? This is what I have so far, but it will only populate the last template.  The first two aren't populating no matter what number I enter.

var a = this.getField("Signing1-9").valueAsString=="1";
var b = this.getField("Signing1-9").valueAsString=="2";
var c = this.getField("Signing1-9").valueAsString=="3";
var d = this.getField("Signing1-9").valueAsString=="4";
var e = this.getField("Signing1-9").valueAsString=="5";
var f = this.getField("Signing1-9").valueAsString=="6";
var g = this.getField("Signing1-9").valueAsString=="7";
var h = this.getField("Signing1-9").valueAsString=="8";
var i = this.getField("Signing1-9").valueAsString=="9";
if(a && b && c)event.value=this.getTemplateAsString("Regulatory").hidden=false;this.getTemplateAsString("Signing1-3").hidden=false;
if(d && e && f)event.value=this.getTemplate("Signing4-6").hidden=false;
else event.value=this.getTemplate("7-9").hidden=false;

 

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