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

Fillable form, adding JavaScript (Conecting two check boxes to produce different commands depending)

Community Beginner ,
Jun 02, 2022 Jun 02, 2022

Greetings,

 

Part 1:

 

I need some help with adobe Acrobat Pro DC. ( Fillable form, adding JavaScript ).

 

Scenario.

 

Assuming I create two check boxes and I want the check boxes to produce a different output just below somewhere depending on what checkbox has been ticked. For example. If a choose checkbox 1, it should output Boy and if i uncheck it, it should go away. Again if I choose checkbox 2, it should output Girl and if i uncheck it, it should go away. Lastly if I choose both checkboxes, it should probably display transgender. ( Something like that ).

 

Part 2:

And another scenario on the same Pdf, imagine one clicks on a checkbox in page 2, but Since they choose something wrong in page one checkbox, an error should appear informing them that previous checkbox checked in page 1 does not allow them to choose this particular checkbox in page 2.

 

I think its an if else statement, but how to connect the two checkboxes to produce commands depending on what has been choosen is still hard for me.

 

Thank you very much.

TOPICS
JavaScript , PDF forms
1.3K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Jun 02, 2022 Jun 02, 2022

Part 1: Lets say your checkboxes are named "checkbox 1" and "checkbox 2" , as 'custom calculation script' of text field where you want to show Boy,Girl,transgender use this:

var b = this.getField("checkbox 1").valueAsString;
var g = this.getField("checkbox 2").valueAsString;
if(b != "Off" && g != "Off")
event.value = "transgender";
else if(b != "Off")
event.value = "Boy";
else if(g != "Off")
event.value = "Girl";
else
event.value = "";

Part 2: Lets say checkbox on page 1 is called "checkbox 1" in checkbox on different page as 'Mouse UP' event add this script:

if(this.getField("checkbox 1").valueAsString != "Off"){
app.alert("Your message goes here");
event.target.value = "Off";}

Change "Your message goes here" to whatever you want error to say.

View solution in original post

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 ,
Jun 02, 2022 Jun 02, 2022

1. You can do it using this code, as the custom calculation script of the text field:

 

var cb1 = this.getField("checkbox 1").isBoxChecked(0);
var cb2 = this.getField("checkbox 2").isBoxChecked(0);
if (cb1&&cb2) event.value = "X";
else if (cb1&&!cb2) event.value = "Boy";
else if (!cb1&&cb2) event.value = "Girl";
else event.value = "";

However, from a user experience perspective, I recommend you let people choose for themselves what they should be called. Don't make assumptions. You will find that you'll save yourself a lot of headaches later on...

 

2. As the Mouse Up event of the second check-box you can enter this code:

if (event.target.value!="Off" && this.getField("checkbox 1").isBoxChecked(0)) {
	app.alert("You should not tick this box since \"checkbox 1\" is already ticked!");
}

View solution in original post

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 ,
Jun 02, 2022 Jun 02, 2022

Part 1: Lets say your checkboxes are named "checkbox 1" and "checkbox 2" , as 'custom calculation script' of text field where you want to show Boy,Girl,transgender use this:

var b = this.getField("checkbox 1").valueAsString;
var g = this.getField("checkbox 2").valueAsString;
if(b != "Off" && g != "Off")
event.value = "transgender";
else if(b != "Off")
event.value = "Boy";
else if(g != "Off")
event.value = "Girl";
else
event.value = "";

Part 2: Lets say checkbox on page 1 is called "checkbox 1" in checkbox on different page as 'Mouse UP' event add this script:

if(this.getField("checkbox 1").valueAsString != "Off"){
app.alert("Your message goes here");
event.target.value = "Off";}

Change "Your message goes here" to whatever you want error to say.

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 ,
Jun 02, 2022 Jun 02, 2022

Thank you very much.

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 ,
Jun 02, 2022 Jun 02, 2022

1. You can do it using this code, as the custom calculation script of the text field:

 

var cb1 = this.getField("checkbox 1").isBoxChecked(0);
var cb2 = this.getField("checkbox 2").isBoxChecked(0);
if (cb1&&cb2) event.value = "X";
else if (cb1&&!cb2) event.value = "Boy";
else if (!cb1&&cb2) event.value = "Girl";
else event.value = "";

However, from a user experience perspective, I recommend you let people choose for themselves what they should be called. Don't make assumptions. You will find that you'll save yourself a lot of headaches later on...

 

2. As the Mouse Up event of the second check-box you can enter this code:

if (event.target.value!="Off" && this.getField("checkbox 1").isBoxChecked(0)) {
	app.alert("You should not tick this box since \"checkbox 1\" is already ticked!");
}
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 ,
Jun 02, 2022 Jun 02, 2022
LATEST

Thank you very much.  i appreciate

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