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

Conditional script not working (radio buttons & text fields)

Community Beginner ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

I have 2 radio button options and 4 text boxes (on my form that are related). When the first is selected, I want only one text box below to appear. When the second is selected, I want the 3 remaining text boxes to appear. I have tried so many different codes, but cannot get it to work. When I use a traditional action to show/hide a field, when one radio button is selected, the text boxes disappear and can't be brought back (they remain hidden). I'm trying to use javascript. Any help is appreciated!

TOPICS
PDF forms

Views

886

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 1 Correct answer

Community Expert , Aug 17, 2018 Aug 17, 2018

You will need to name the buttons and fields consistently

Say the button is called Button and the choices are R1 and R2.

Call the fields Field1, Field2, Field3, Field4.

var Q = this.getField("Button");

var A = this.getField("Field1");

var B = this.getField("Field2");

var C = this.getField("Field3");

var D = this.getField("Field4");

if (Q.value === "R1") {

     A.hidden = false; 

     B.hidden = true; 

     C.hidden = true; 

     D.hidden = true;      

}

if (Q.value === "R2") {

     A.hidden = true;    

   

...

Votes

Translate

Translate
LEGEND ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

Post what you've tried and list the exact field names of all of the fields involved.

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 ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

Thank you. Below are the scripts I tried.

1.

this.getField("Annual Amount").display = (event.target.value=="Annually") ? display.visible : display.hidden;

this.getField("Fall Amount").display = (event.target.value=="Semesterly") ? display.visible : display.hidden;

this.getField("Spring Amount ").display = (event.target.value==" Semesterly ") ? display.visible : display.hidden; this.getField("Summer Amount ").display = (event.target.value==" Semesterly ") ? display.visible : display.hidden;

2.

{  var a = this.getField("Distribution").value;

   function ShowMe()

   if (a == "Annually")

   {      this.getField(“Fall Amount").display = display. hidden;

      this.getField(“Spring Amount").display = display.hidden;

      this.getField(“Summer Amount").display = display.hidden;   }

3.

if (this.getField("Annually").value=="Yes") {

this.getField("Fall Amount").readonly = true;

this.getField("Spring Amount").readonly = true;

this.getField("Summer Amount").readonly = true;}

4.

var v = this.getField("Distribution").valueAsString; 

this.getField("Annual Amount").display = (v=="Semesterly") ? display.visible : display.hidden; 

this.getField("Fall Amount").display = (v=="Annually") ? display.visible : display.hidden; 

this.getField("Spring Amount").display = (v=="Annually") ? display.visible : display.hidden; 

this.getField("Summer Amount").display = (v=="Annually") ? display.visible : display.hidden; 

5.

var f = this.getField("Annual Amount");

f.hidden = (Annually=off);

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 ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

You will need to name the buttons and fields consistently

Say the button is called Button and the choices are R1 and R2.

Call the fields Field1, Field2, Field3, Field4.

var Q = this.getField("Button");

var A = this.getField("Field1");

var B = this.getField("Field2");

var C = this.getField("Field3");

var D = this.getField("Field4");

if (Q.value === "R1") {

     A.hidden = false; 

     B.hidden = true; 

     C.hidden = true; 

     D.hidden = true;      

}

if (Q.value === "R2") {

     A.hidden = true;    

     B.hidden = false; 

     C.hidden = false; 

     D.hidden = false;      

}

you need the code to be on both radio buttons, i would put them on the Mouse Release

You can also affect the required in the same way as the hidden property (but remember having it hidden and required leads to frustration)

Hope that helps

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 ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

Thank you Lukas! It worked!!!

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 ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

LATEST

Keeping all the variables in the beginning makes it easier to reuse and trouble shoot

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