You are viewing limited content. For full access, please sign in.

Question

Question

JavaScript for clearing a field based on a checkbox is recognizing the value of the checkbox as undefined

asked on August 5, 2024 Show version history

I am trying to create a form with a series of formulas in the classic designer. The formulas will act on the values in two fields. For this process there will be a field and a corresponding checkbox that will compare to another field and corresponding checkbox. The field will contain a number value and if the item is included, then the checkbox will be selected. When the checkbox is selected the number field needs to be cleared. This needs to occur whether the number is entered first and then the box is checked or if the box is checked first and then a number is entered. 

 

The particular issue that I am running to at the moment is that the checkbox value is returning as undefined. 

 

 

Here is the current Java that has been added to the form. Currently I am using a test copy that only has this Java present to ensure that there are not any conflicts with existing code on the original form.

 

0 0

Replies

replied on August 5, 2024

As a suggestion, you should paste your code here using the "{...} code" button.  Doing a screenshot like that means we can't try to test any of your code without retyping it all.

Even without testing your code, I can see that you have some issues with how you are referencing the fields via the class names: checkbox-B10 and field-B10.  Those class names are referencing the entire field structure (it's a div element with a bunch of components like label, helptext, parsley errors, input elements, etc., etc.).  You need to narrow the code to just targeting the input elements within those fields.  You need to change the code to target the specific input elements within those classes instead of the entire field itself.  Like this: $(".checkbox-B10 input") and $(".field-B10 input").

I can't say for sure that there are not more issues without testing your code, but that should at least be a start.

1 0
replied on August 6, 2024

Matthew that did solve my problem. Thanks for the help! I will be sure to keep in mind that its easiest to assist when you are able to copy the code for next time!

1 0
replied on August 6, 2024

I'm glad to hear that resolved the issue.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.