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

PDF Form - Script to Auto Check a CheckBox when the Value in a Text Field is Greater than $0.

Community Beginner ,
May 28, 2020 May 28, 2020

Dear All,

I like to seek your help for a script to auto check a checkbox when a a text field is greater than $0.

My script as below but doesn't work.

 

var TextField = number(this.getField("=TextField").value);
if (TextField = 0) {

this.getField("CheckBox").checkThisBox(0, true);
} else {
this.getField("CheckBox").checkThisBox(0, false);
}

 

But it doesn't work. Appreciate the guidance here.

TOPICS
Create PDFs , How to , PDF forms
3.1K
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
1 ACCEPTED SOLUTION
Community Expert ,
May 28, 2020 May 28, 2020

What are the actual names of your fields?

You have multiple errors in your code...

- It's Number(), not number().

- It's ==0, not =0. Also, if you want to check if the value is greated then zero then you should use >0.

And where did you place this code?

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
Participant ,
May 28, 2020 May 28, 2020

A couple issues with your code.

1. don't wrap 'this.getField(=TextField").value in  number() and

2. you have an '=' sign in this.getField(=TextField").value. Remove it.

3. Your code should be checking for a value of the TextField > 0, not = 0.

4. Make sure the text field is formatted to number so that only numbers can be entered if it is your intent to only have numbers entered.

Your code should be:

var TextField = this.getField("TextField").value;

if (TextField > 0) {
this.getField("CheckBox").checkThisBox(0, true);
} else {
this.getField("CheckBox").checkThisBox(0, false);
}

 

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 ,
May 28, 2020 May 28, 2020

What are the actual names of your fields?

You have multiple errors in your code...

- It's Number(), not number().

- It's ==0, not =0. Also, if you want to check if the value is greated then zero then you should use >0.

And where did you place this code?

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 ,
May 28, 2020 May 28, 2020
LATEST

Hi try67,

 

My sincere apologies. I lost touch with javascript and forgotten about double equality. The small "n" was a typo.

 

My text field is "Text4". And checkbox is "CheckBox27".  I rewrite as below and has pasted it under custom calculation script in text field "Text4" and it is working! Thank you so  much for the guidance.

 

var Text4 = Number(this.getField("Text4").value);
if (Text4 == 0) {

this.getField("CheckBox27").checkThisBox(0, false);
} else {
this.getField("CheckBox27").checkThisBox(0, true);
}

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