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

If yes, text should display texta, if no, text should display textb on form

Community Beginner ,
Feb 15, 2016 Feb 15, 2016

I have a form, that if you select yes, phrase one will appear,  if you select no, phrase 2 will appear.

I have one check box called "choice" and an empty text box called texBox.

I have tried these javascripts: inside Actions -> Mouse Up -> Run a javaScript.

Using Adobe Acrobat Pro DC

--------------------- attempt 1 --------------------------

var f = this.getField("choice").value;

if(f ="yes")

{textBox.value = "yes";}

else if(f !== "yes")

{textBox.value ="no";}

So If I click on the check box, the box should say yes.

-------------------- attempt 2 -------------------------

another attempt, using differant variables then above.

var g = this.getField("clickMe2").value;

if(g){textBox2.value = "true";}

else{textBox2.value = "false";}

-------------- attempt 3 using a drop down for yes and no  (would not want to do it this way) -----------------------

var h=this.getField("List Box8").value;

if(f =="Yes"){

this.getField("Text9").value = "YYes";}

if(f == "No"){

this.getField("Text9").value = "NNo";}

This seems so simple, but apparently not.   Please advise.

I would prefer the check box to be a pair of radio buttons,  labeled yes and no, but that did not work, so thought it would be easier just to do a check box labeled yes. which would default at No.

I would really prefer all of the questions on page one only to appear if yes was selected, but again, too complicated for me at this point.

TOPICS
Acrobat SDK and JavaScript , Windows
612
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

correct answers 1 Correct answer

Community Expert , Feb 15, 2016 Feb 15, 2016

Set up two radio-buttons with "Yes" and "No" as their values under "Radio Button Choice" in Properties - Options.

Then apply this code as their Mouse Up script:

var f = this.getField("Text9");

if (event.target.value=="Off") f.value = "";

else f.value = event.target.value;

Translate
Community Expert ,
Feb 15, 2016 Feb 15, 2016

‌The value of a checked checkbox is "Yes" or the export value.

The value of a unchecked checkbox is "Off".

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 Beginner ,
Feb 15, 2016 Feb 15, 2016
LATEST

Thanks Bernd Alheit,   I did not know about the value of "Off".   While this answer is correct, the answer by try67 better fit my needs of the radio button.  

Thanks both of you for help.

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 ,
Feb 15, 2016 Feb 15, 2016

Set up two radio-buttons with "Yes" and "No" as their values under "Radio Button Choice" in Properties - Options.

Then apply this code as their Mouse Up script:

var f = this.getField("Text9");

if (event.target.value=="Off") f.value = "";

else f.value = event.target.value;

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