Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!");
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thank you very much.
Copy link to clipboard
Copied
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!");
}
Copy link to clipboard
Copied
Thank you very much. i appreciate

