Copy link to clipboard
Copied
Hello, I am a beginner. I have a value that is a weight in "kg" to be entered on the PDF form I want a checkbox or a radio button to be ticked automatically depending on 3 ranges of the weight entered:
If you use check-boxes with the same names and export values then you could use this script as the custom validation script "kg" to achieve it:
var kg = Number(event.value);
this.getField("rb1").checkThisBox(0, kg<1);
this.getField("rb2").checkThisBox(0, kg>=1 && kg<=3);
this.getField("rb3").checkThisBox(0, kg>3);
As the custom calculation of "C" enter the following:
var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);
event.value = Math.min(3, v);
You can use this, then:
if (this.getField("CB1").valueAsString=="Off") event.value = "";
else {
var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);
event.value = Math.min(3, v);
}
Copy link to clipboard
Copied
What's the name of the radio-button fields, and what are their export values?
Copy link to clipboard
Copied
the names of the radio buttons are
rb1
rb2
rb3
the corresponding values:
1.5 mL
3.25 mL
5 mL
Copy link to clipboard
Copied
What about if the "kg" field is empty?
Copy link to clipboard
Copied
PS. you should either convert the fields to check-boxes or give them all the same name.
Copy link to clipboard
Copied
checkboxes should be Ok too
Copy link to clipboard
Copied
If you use check-boxes with the same names and export values then you could use this script as the custom validation script "kg" to achieve it:
var kg = Number(event.value);
this.getField("rb1").checkThisBox(0, kg<1);
this.getField("rb2").checkThisBox(0, kg>=1 && kg<=3);
this.getField("rb3").checkThisBox(0, kg>3);
Copy link to clipboard
Copied
Fantastic! it worked very well, thanks a lot.
I have another variable that is a simple mutiplication of 2 others, and I want the result if exceeding numer 3, to just give the number 3 itself:
A*B=C
if C>3 then C=3
Thanks a lot for your support and help.
Copy link to clipboard
Copied
As the custom calculation of "C" enter the following:
var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);
event.value = Math.min(3, v);
Copy link to clipboard
Copied
Great!
If I want the result of this script to run at "C" only when I check a checkbox named "CB1", how should I add this condition?
Thanks for your patience.
Copy link to clipboard
Copied
Do you mean it should only show this result if CB1 is ticked?
Copy link to clipboard
Copied
yes exactly
Copy link to clipboard
Copied
So what should the value be when it's not ticked?
Copy link to clipboard
Copied
it should be empty
Copy link to clipboard
Copied
You can use this, then:
if (this.getField("CB1").valueAsString=="Off") event.value = "";
else {
var v = Number(this.getField("A").valueAsString) * Number(this.getField("B").valueAsString);
event.value = Math.min(3, v);
}
Copy link to clipboard
Copied
Wonderful!
Thanks for taking me patiently step by step, I do appreciate your help.
I learned from you and I am grateful to you.
Thanks
Copy link to clipboard
Copied
kg can't be empty and can't be zero