Expand my Community achievements bar.

SOLVED

Using a Text Field to check/uncheck checkbox

Avatar

Former Community Member

Hi,

I have a series of check boxes in my form. I have been trying to get it so one of the check boxes automatically checks/unchecks if text is entered or fully removed from a text field.

I can get it to 'check' when text is entered, but nothing I have tried is 'unchecking' when the text is removed and the field is empty.

The most logical script I tried seems to be this...

In the Change event of the text field (both the checkbox (named 'other')and the text field are wrapped in the same subform):

if

((this.rawValue != "") || (this.raw.Value != "null")) {

other.rawValue = "1";

}

else {

other.rawValue = "0";

}

This checks when a text character is typed into the field, but doesn't uncheck when they are deleted. I tried reversing it so the 'if' was rawValue "0" (using == instead of !=) and the else was rawValue "1" - and both ways round in the 'exit' event - again 'check' but no 'uncheck'. I have tried every combination of if/if and if/else I can think of.

I know I must be missing something obvious, but could anyone explain why this doesn't work, and how I can script it so that it does work?

Thank you!

TW

1 Accepted Solution

Avatar

Correct answer by
Level 6

Try this on Change event of the textfield.

var txtLength = xfa.event.newText.length;

if(txtLength > 0 ) {

CheckBox1.rawValue = "1";

}

else {

CheckBox1.rawValue = "0";

}

Hope this helps.

-Raghu.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 6

Try this on Change event of the textfield.

var txtLength = xfa.event.newText.length;

if(txtLength > 0 ) {

CheckBox1.rawValue = "1";

}

else {

CheckBox1.rawValue = "0";

}

Hope this helps.

-Raghu.

Avatar

Former Community Member

Hi Raghu,

Huge thank you - that worked perfectly.

I really appreciate such quick help!