Skip to main content
Participant
November 3, 2018
Answered

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

  • November 3, 2018
  • 2 replies
  • 5909 views

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?

This topic has been closed for replies.
Correct answer firstbaptistchur50824275

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");

    }

}


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.

2 replies

try67
Community Expert
Community Expert
November 3, 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;

Participant
November 4, 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";

Bernd Alheit
Community Expert
Community Expert
November 4, 2018

Remove this code.

Inspiring
November 3, 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.