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

Checkbox conditioned upon value in another text field (or two fields)

Explorer ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

How to make these two groups of checkboxes happen??  (note - my checkbox "group" is set up with same name but different choices 'Yes and No' so that they act more like radio buttons)  These two checkboxes are independant of each other.

CheckBox1 - Check Yes if A4 >= A5, else No

CheckBox2 - if A7 is "" then "", Check Yes if A7>=A3 or Amount7>=M, else No

 

Based upon other calcs you have helped me on, I've got my variables set up (I think) but how do I write the rest of the query?

 

var CB1 = this.getField("CheckBox1");  //  Yes or No;

var CB2 = this.getField("CheckBox2"); //  Yes or No;

var A1 = this.getField("Amount1").valueAsString; // amount ;        .......through A11

var M = this.getField("Minimum").valueAsString; // minimum amount;

{

     A3 = Number(A3);

     A4 = Number(A4);

     A5 = Number(A5);

     A7 = Number (A7);

     M = Number (M);

if (CB1 = ...............now what?

If it would be easier to change the checkboxes to radio buttons, I could.  But would prefer not to.

 

TIA ~ Michelle

 

TOPICS
Acrobat SDK and JavaScript

Views

1.1K

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 , Dec 13, 2019 Dec 13, 2019

So, do you want the checkboxes to get checked automatically based on the entered values?

Where is this script? is it a calculation?

 

A checkbox is checked when it's value is the same as the Export value

Here's some simple code for checking your first box

if(A4 >= A5)
    CB1.value = "Yes";
else
    CB1.value = "No";

Votes

Translate

Translate
Community Expert , Dec 13, 2019 Dec 13, 2019

After A7 is converted to a number it will not be an empty string, i.e. "".   Empty strings are converted to 0.

If CB2 is a checkbox then it does not make sense to set it to an empty string. I imagine you are doing this to uncheck the checkboxes, and it works because "" is not a valid value, so Acrobat converts it to "Off". What the code should do is set CB2.value = "Off";   This is important  because other PDF viewers are not obligated to convert invalid checkbox values to "Off". In all likely h

...

Votes

Translate

Translate
Community Expert ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

So, do you want the checkboxes to get checked automatically based on the entered values?

Where is this script? is it a calculation?

 

A checkbox is checked when it's value is the same as the Export value

Here's some simple code for checking your first box

if(A4 >= A5)
    CB1.value = "Yes";
else
    CB1.value = "No";
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

Thank you for your direction, Thom.  I created hidden fields to contain the calculations - CB1Decision and CB2Decision.  So far, it appears to be working perfectly.  But if you see an problem, let me know.  i've found in the past that what I thought was perfect was only working by default and undera scenario I hadn't tested it bombed!!

Again - thanks so much for your help!!!

 

for CB1Decision:

var CB1 = this.getField("CheckBox1");  //  Yes or No;
var A4 = this.getField("Amount4").valueAsString; // Policy amount;
var A5 = this.getField("Amount5").valueAsString; // Replacement cost ;

{
    A4 = Number(A4);
    A5 = Number(A5);
    if (A4=="" && A5=="") event.value = "";     

    else if (A4 >= A5) CB1.value = "Yes";
    else CB1.value = "No";
}

for CB2Decision:

var CB2 = this.getField("CheckBox2");  //  Yes or No;
var A3 = this.getField("Amount3").valueAsString; // Total Liens;
var A7 = this.getField("Amount7").valueAsString; // Replacement cost per unit;
var M = this.getField("Maximum").valueAsString; // Maximim NFIP policy per unit;

{
     A3 = Number(A3);
     A7 = Number(A7);
     M = Number(M);
    
     if (A7 == "") CB2.value = "";
     else if(A7 >= A3) CB2.value = "Yes";
     else if (A7 >= M) CB2.value = "Yes";
     else CB2.value = "No";
}

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 ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

After A7 is converted to a number it will not be an empty string, i.e. "".   Empty strings are converted to 0.

If CB2 is a checkbox then it does not make sense to set it to an empty string. I imagine you are doing this to uncheck the checkboxes, and it works because "" is not a valid value, so Acrobat converts it to "Off". What the code should do is set CB2.value = "Off";   This is important  because other PDF viewers are not obligated to convert invalid checkbox values to "Off". In all likely hood it's not a real problem, but by doing it correctly you are guarenteeing that it never will be a problem.  

 

You could also combine the cases where CB2 is set to "Yes".  

 

 if (A7 == 0) CB2.value = "Off";
 else if((A7 >= A3) || (A7 >= M)) CB2.value = "Yes";
 else CB2.value = "No";

 

Another variation is to combine both scripts into one calculation script. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Explorer ,
Dec 13, 2019 Dec 13, 2019

Copy link to clipboard

Copied

Wow - as I was figuring out that I had found the hidden bomb to my query, your post popped up.  I put in your code and if fixed it right up!!  Trying to train my brain from Excel to Adobe has been an adventuer.  Your explanations are so very helpful and will go into my Adobe How-to bible.  I know I'll be using your tips many more times in the future!  YOU ARE THE BEST!

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
Explorer ,
Dec 14, 2019 Dec 14, 2019

Copy link to clipboard

Copied

Hi Thom,

While perusing this Support site for tips/tricks, I read one of your answers and you referenced a website for additional info.  It's your site - No wonder you know so much!  I watched several of the free videos and knew I had to join right away.  The time saved from searching the web for answers is well worth the membership cost for me.  I look forward to jumping in and learning.  Thanks so much. 

https://www.pdfscripting.com/public/Free_Videos.cfm

 

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 ,
Dec 14, 2019 Dec 14, 2019

Copy link to clipboard

Copied

LATEST

Thank you for the kind words Michell. I hope you find the site helpful. Please let us know if there is any information you'd like to see that isn't there. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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