Immediately check a checkbox when text is entered in a field

Mentor ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

I have a checkbox with the name "Completed High School?", a text field with the name "Number of Years Completed", and radio button group called "High School Credentials". Ideally, someone would check the checkbox first and then enter the number of years completed and select a radio button option second. But in case they overlook the checkbox and go straight for the other fields, I would like the checkbox to be checked automatically, as soon as text is entered in the field, or as soon as a radio button option is selected.

 

The part where the checkbox gets checked when you select a radio button option is working. It's the text field that's giving me trouble.

 

education.png

 

I placed this custom validation script on the text field:

 

 

if (event.target.value != "") this.getField("Completed High School?").checkThisBox(0, true);

 

 

But that doesn't work like I expected it to; it does nothing at all.

 

I also have this mouseup action on the checkbox:

 

 

if (event.target.value == "Off") {
this.getField("Number of Years Completed").value = "";
this.getField("High School Credentials").value = "Off";
}

 

 

 

 

 

TOPICS
JavaScript , PDF forms

Views

44

Likes

Translate

Translate

Report

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
Mentor ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

Ahh, I think I figured it out. For reasons that are still not clear to me, I should have written event.value instead of event.target.value.

Likes

Translate

Translate

Report

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 ,
Aug 11, 2022 Aug 11, 2022

Copy link to clipboard

Copied

LATEST

That's because in the Validation event event.target.value refers to the field's old value (because the new one has not been accepted yet), while event.value refers to its new value, the one the user just entered.

Likes

Translate

Translate

Report

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