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

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

}

}


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

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.