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

If checkbox is "unchecked" how do i make textbox associated with it have a numeric value to be 0?

Community Beginner ,
Nov 03, 2018 Nov 03, 2018

I have a CheckBox36 and a Text28 box. If checkbox36 is "checked" then text28 is populated with a specific numeric value "100".  I am using this action in checkbox36 properties:   event.value = this.getField("Text28").value = "100"; this works great.

How do make "Text28" have "0" value when i "uncheck" checkbox36?

TOPICS
PDF forms
5.6K
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 Beginner ,
Nov 04, 2018 Nov 04, 2018
LATEST

THANK YOU!! it works now. I had to correct the spelling of the name of my Check Box - then it worked.  Thank you for being patient with me.

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
LEGEND ,
Nov 03, 2018 Nov 03, 2018

You need to use the "if ... them ... " conditional statement to test the value of the check box and then execute the block of code base on the value.

Since the value of the check box is "Off" when not checked, I would test for that value. When "Off" the text field is set to zero if not "Off" the text field is set to 100.

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 ,
Nov 03, 2018 Nov 03, 2018

Your code is not correct. You should use this code as the custom calculation script of the text field:

event.value = (this.getField("checkbox36").valueAsString=="Off") ? 0 : 100;

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 ,
Nov 04, 2018 Nov 04, 2018

thank you for your help; but it did not work as desired.

I entered the code you gave in the custom calculation script of the text field of textbox28.  Then i previewed my form.  I checked checkbox36 and 100 came up in text28.  that is what i want.  But when I uncheck checkbox36, the 100 still did not go away in text28. 

Do i need to remove the code I had in checkbox36?  It is   event.value = this.getField("Text28").value = "100";

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 ,
Nov 04, 2018 Nov 04, 2018

Remove 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
LEGEND ,
Nov 04, 2018 Nov 04, 2018

Open the JavaScript console, <Ctrl> + J, and see if there are any messages. This may provide a hint as to what the problem is.

JavaScript is case sensitive an fields must be spelled as they are named.

You can try the following code in the custom calculation for the Texxt28 field:

try {

if(this.getField("CheckBox36").value == "Off") {

event.value = 0;

} else {

event.value = 100;

}

} catch(error) {

console.show();

for(var i in error) {

console.println(i + ": " + error) + " " + error.i;

}

console.println("exitMessage: " + error.extMessage);

console.println("message: " + error.message);

console.println("name: " + error.name);

if(this.getField("CheckBox36") == null) {

console.println("Error in field name");

}

}

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 ,
Nov 04, 2018 Nov 04, 2018

I placed the new code you gave me in Text28.  I goth the following syntax error:

catch without try 7: at line 8

what does that mean?  i don't know how to fix that...

thank you again for your help

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 ,
Nov 04, 2018 Nov 04, 2018

this was highlighted when i got the syntax error:

console.show();

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 ,
Nov 04, 2018 Nov 04, 2018

Are you sure you copied the entire code? Copy it from here:

try {

    if (this.getField("CheckBox36").value == "Off") {

        event.value = 0;

    } else {

        event.value = 100;

    }

} catch(error) {

    console.show();

    for(var i in error) {

        console.println(i + ": " + error) + " " + error.i;

    }

    console.println("exitMessage: " + error.extMessage);

    console.println("message: " + error.message);

    console.println("name: " + error.name);

    if (this.getField("CheckBox36") == null) {

        console.println("Error in field name");

    }

}

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 ,
Nov 04, 2018 Nov 04, 2018
LATEST

THANK YOU!! it works now. I had to correct the spelling of the name of my Check Box - then it worked.  Thank you for being patient with me.

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